Alan Agius 5395cecf59 refactor: remove deprecate protractor elementExplorer
Protractor `elementExplorer` debugger and element explorer cannot be used for Node.js 8+ since it relied on `_debugger` module.

In protractor version 5, this resulted in the below error:
```
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.
[10:25:35] I/direct - Using ChromeDriver directly...
[10:25:37] I/protractor -
[10:25:37] I/protractor - ------- Element Explorer -------
[10:25:37] I/protractor - Starting WebDriver debugger in a child process. Element Explorer is still beta, please report issues at github.com/angular/protractor
[10:25:37] I/protractor -
[10:25:37] I/protractor - Type <tab> to see a list of locator strategies.
[10:25:37] I/protractor - Use the `list` helper function to find elements by strategy:
[10:25:37] I/protractor -   e.g., list(by.binding('')) gets all bindings.
[10:25:37] I/protractor -
***********************************************************
* WARNING: _debugger module not available on Node.js 8    *
* and higher.                                             *
*                                                         *
* Use 'debugger' keyword instead:                       *
* https://goo.gl/MvWqFh                                   *
***********************************************************
/Users/alanagius/cli-repos/demo-several/node_modules/protractor/built/debugger/debuggerCommons.js:14
  throw e;
  ^

Error: Cannot find module '_debugger'
Require stack:
- /Users/alanagius/cli-repos/demo-several/node_modules/protractor/built/debugger/debuggerCommons.js
- /Users/alanagius/cli-repos/demo-several/node_modules/protractor/built/debugger/clients/explorer.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/alanagius/cli-repos/demo-several/node_modules/protractor/built/debugger/debuggerCommons.js:3:18)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/alanagius/cli-repos/demo-several/node_modules/protractor/built/debugger/debuggerCommons.js',
    '/Users/alanagius/cli-repos/demo-several/node_modules/protractor/built/debugger/clients/explorer.js'
  ]
}
```

but in protractor version 7, this logic was removed.

BREAKING CHANGE:
Protractor builder elementExplorer option has been removed. This was not compatable with the Node.Js versions that the Angular CLI supports. See: https://github.com/angular/protractor/blob/master/docs/debugging.md#enabled-control-flow for an alternative debugging methods.
2020-05-15 14:44:45 +01:00

124 lines
3.2 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { JsonObject, JsonValue, isJsonObject, workspaces } from '@angular-devkit/core';
import { Rule } from '@angular-devkit/schematics';
import { updateWorkspace } from '../../utility/workspace';
import { Builders, ProjectType } from '../../utility/workspace-models';
export default function (): Rule {
return updateWorkspace(workspace => {
// Remove deprecated CLI root level options
removeDeprecatedCLIOptions(workspace.extensions);
for (const [, project] of workspace.projects) {
// Project level
removeDeprecatedCLIOptions(project.extensions);
if (project.extensions.projectType !== ProjectType.Application) {
// Only interested in application projects since these changes only effects application builders
continue;
}
for (const [, target] of project.targets) {
// Only interested in Angular Devkit builders
if (!target?.builder.startsWith('@angular-devkit/build-angular')) {
continue;
}
let optionsToRemove: Record<string, undefined> = {
evalSourceMap: undefined,
skipAppShell: undefined,
profile: undefined,
elementExplorer: undefined,
};
if (target.builder === Builders.Server) {
optionsToRemove = {
...optionsToRemove,
vendorChunk: undefined,
commonChunk: undefined,
};
}
// Check options
if (target.options) {
target.options = {
...updateVendorSourceMap(target.options),
...optionsToRemove,
};
}
// Go through each configuration entry
if (!target.configurations) {
continue;
}
for (const configurationName of Object.keys(target.configurations)) {
target.configurations[configurationName] = {
...updateVendorSourceMap(target.configurations[configurationName]),
...optionsToRemove,
};
}
}
}
});
}
type TargetOptions = workspaces.TargetDefinition['options'];
function updateVendorSourceMap(options: TargetOptions): TargetOptions {
if (!options) {
return {};
}
const { vendorSourceMap: vendor, sourceMap = true } = options;
if (vendor === undefined) {
return options;
}
if (sourceMap === true) {
return {
...options,
sourceMap: {
styles: true,
scripts: true,
vendor,
},
vendorSourceMap: undefined,
};
}
if (typeof sourceMap === 'object') {
return {
...options,
sourceMap: {
...sourceMap,
vendor,
},
vendorSourceMap: undefined,
};
}
return {
...options,
vendorSourceMap: undefined,
};
}
function removeDeprecatedCLIOptions(extensions: Record<string, JsonValue | undefined>) {
const cliOptions = extensions?.cli;
if (cliOptions && isJsonObject(cliOptions) && isJsonObject(cliOptions.warnings)) {
(cliOptions.warnings as Partial<JsonObject>) = {
...cliOptions.warnings,
typescriptMismatch: undefined,
};
}
}