Skip to content

Commit

Permalink
chore: moved to yarn workspaces to have a better testing suite
Browse files Browse the repository at this point in the history
This is done because we want to resolve internal packages during e2e without using shim code.
  • Loading branch information
ematipico committed Feb 17, 2020
1 parent 513341b commit 4059b2d
Show file tree
Hide file tree
Showing 29 changed files with 93 additions and 56,933 deletions.
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
// transformIgnorePatterns: ['<rootDir>.*(node_modules)(?!.*webpack-cli.*).*$'],
testEnvironment: 'node',
collectCoverage: true,
coverageReporters: ['json', 'html', 'cobertura'],
transform: {
'^.+\\.(ts)?$': 'ts-jest',
},
testRegex: ['/__tests__/.*\\.(test.js|test.ts)$', '/test/.*\\.(test.js|test.ts)$'],
moduleFileExtensions: ['ts', 'js', 'json'],
};
2 changes: 2 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"lerna": "3.20.2",
"packages": ["packages/*"],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
"version": {
"message": "chore(release): publish %s",
Expand Down
18,024 changes: 0 additions & 18,024 deletions package-lock.json

This file was deleted.

28 changes: 4 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "4.0.0-beta.3",
"description": "CLI for webpack & friends",
"license": "MIT",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/webpack/webpack-cli.git"
Expand All @@ -26,6 +27,9 @@
"lib",
"bin/cli.js"
],
"workspaces": [
"./packages/*"
],
"scripts": {
"bootstrap": "npm run clean:all && npm install && lerna bootstrap",
"build": "tsc",
Expand Down Expand Up @@ -109,30 +113,6 @@
}
]
},
"jest": {
"testPathIgnorePatterns": [
"/node_modules/"
],
"testEnvironment": "node",
"collectCoverage": true,
"coverageReporters": [
"json",
"html",
"cobertura"
],
"transform": {
"^.+\\.(ts)?$": "ts-jest"
},
"testRegex": [
"/__tests__/.*\\.(test.js|test.ts)$",
"/test/.*\\.(test.js|test.ts)$"
],
"moduleFileExtensions": [
"ts",
"js",
"json"
]
},
"nyc": {
"include": [
"./cli.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const GroupHelper = require('../packages/cli/lib/utils/GroupHelper');
const GroupHelper = require('../lib/utils/GroupHelper');

describe('GroupHelper', function() {
it('should return undefined', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ZeroConfigGroup = require('../packages/cli/lib/groups/ZeroConfigGroup');
const ZeroConfigGroup = require('../lib/groups/ZeroConfigGroup');

describe('GroupHelper', function() {
it('should load the dev zero config', () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/__tests__/command/external.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const ExternalCommand = require('../../lib/commands/external')

describe('external command', () => {
it('should check existence of package', () => {
const exists = ExternalCommand.checkIfPackageExists('info')

expect(exists).toBeFalsy();
})
})
1 change: 0 additions & 1 deletion packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ if (!semver.satisfies(process.version, version)) {

const [, , ...rawArgs] = process.argv;
const { cliArgs, nodeArgs } = parseArgs(rawArgs);
// eslint-disable-next-line node/no-unpublished-require
const bootstrapPath = require.resolve('../lib/bootstrap');

execa('node', [...nodeArgs, bootstrapPath, ...cliArgs], { stdio: 'inherit' }).catch(e => {
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/lib/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const WebpackCLI = require('./webpack-cli');
const { core, commands } = require('./utils/cli-flags');
const cmdArgs = require('command-line-args');
const logger = require('./utils/logger');

require('./utils/process-log');
Expand Down Expand Up @@ -61,7 +60,7 @@ async function runCLI(cli, commandIsUsed) {
return await cli.runCommand(commandIsUsed, ...args);
} else {
try {
args = cmdArgs(core, { stopAtFirstUnknown: false, partial: true });
args = cli.commandLineArgs(core, { stopAtFirstUnknown: false, partial: true });
if (args._unknown) {
resolveNegatedArgs(args);
args._unknown
Expand Down Expand Up @@ -98,7 +97,7 @@ async function runCLI(cli, commandIsUsed) {
const newArgKeys = Object.keys(argsMap).filter(arg => !keysToDelete.includes(argsMap[arg].pos));
// eslint-disable-next-line require-atomic-updates
process.argv = newArgKeys;
args = cmdArgs(core, { stopAtFirstUnknown: false, partial: true });
args = cli.commandLineArgs(core, { stopAtFirstUnknown: false, partial: true });

await cli.run(args, core);
process.stdout.write('\n');
Expand Down
13 changes: 8 additions & 5 deletions packages/cli/lib/commands/external.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ class ExternalCommand {
});
}

/**
*
* @param extName
* @returns {boolean}
*/
static checkIfPackageExists(extName) {
try {
const path = require('path');
const pathForCmd = path.resolve(process.cwd(), 'node_modules', packagePrefix, extName);
require.resolve(pathForCmd);
return pathForCmd;
require(`${packagePrefix}/${extName}`);
return true;
} catch (err) {
return false;
}
Expand Down Expand Up @@ -65,7 +68,7 @@ class ExternalCommand {
if (!pkgLoc) {
pkgLoc = await ExternalCommand.promptInstallation(scopeName, name);
}
return pkgLoc ? require(pkgLoc).default(...args) : null;
return pkgLoc ? require(scopeName).default(...args) : null;
}
}

Expand Down
Loading

0 comments on commit 4059b2d

Please sign in to comment.