feat(react): remove references to angular devkit from @nrwl/web (#4705)

This commit is contained in:
Jason Jean 2021-02-04 16:56:44 -05:00 committed by GitHub
parent 7372920bef
commit f880bd295d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 72 additions and 205 deletions

View File

@ -9,7 +9,7 @@ import {
stripIndent,
stripIndents,
} from '@angular-devkit/core/src/utils/literals';
import { initRootBabelConfig } from '@nrwl/web/src/utils/rules';
import { initRootBabelConfig } from '../utils/rules';
import { addDepsToPackageJson, formatFiles } from '@nrwl/workspace';
let addedEmotionPreset = false;

View File

@ -7,7 +7,7 @@
"excludedFiles": ["./src/migrations/**"],
"rules": {
"no-restricted-imports": [
"warn",
"error",
"@nrwl/workspace",
"@angular-devkit/core",
"@angular-devkit/schematics",

View File

@ -1,5 +1,4 @@
{
"$schema": "@angular-devkit/architect/src/builders-schema.json",
"builders": {
"build": {
"implementation": "./src/builders/build/compat",
@ -17,7 +16,7 @@
"description": "Serve a web application"
},
"file-server": {
"implementation": "./src/builders/file-server/file-server.impl",
"implementation": "./src/builders/file-server/compat",
"schema": "./src/builders/file-server/schema.json",
"description": "Serve a web application from a folder"
}

View File

@ -32,10 +32,6 @@
"@nrwl/devkit": "*",
"@nrwl/jest": "*",
"@nrwl/linter": "*",
"@angular-devkit/architect": "~0.1100.1",
"@angular-devkit/build-webpack": "~0.1100.1",
"@angular-devkit/core": "~11.0.1",
"@angular-devkit/schematics": "~11.0.1",
"@babel/core": "7.9.6",
"@babel/preset-env": "7.9.6",
"@babel/plugin-proposal-class-properties": "7.8.3",

View File

@ -0,0 +1,5 @@
import { convertNxExecutor } from '@nrwl/devkit';
import fileServerExecutor from './file-server.impl';
export default convertNxExecutor(fileServerExecutor);

View File

@ -1,11 +1,10 @@
import { JsonObject } from '@angular-devkit/core';
import watch from 'node-watch';
import { exec, execSync } from 'child_process';
import { ExecutorContext } from '@nrwl/devkit';
import ignore from 'ignore';
import { readFileSync } from 'fs-extra';
export interface FileServerOptions extends JsonObject {
export interface FileServerOptions {
host: string;
port: number;
ssl: boolean;
@ -141,7 +140,7 @@ export default async function (
process.stderr.write(chunk);
});
return new Promise((res) => {
return new Promise<{ success: boolean }>((res) => {
serve.on('exit', (code) => {
if (code == 0) {
res({ success: true });

View File

@ -5,7 +5,6 @@ import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import { ProgressPlugin } from 'webpack';
import { BuildBuilderOptions } from './types';
import { normalize } from '@angular-devkit/core';
import CircularDependencyPlugin = require('circular-dependency-plugin');
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
@ -21,7 +20,7 @@ describe('getBaseWebpackPartial', () => {
tsConfig: 'tsconfig.json',
fileReplacements: [],
root: '/root',
sourceRoot: normalize('/root/src'),
sourceRoot: '/root/src',
statsJson: false,
};
(<any>(

View File

@ -167,7 +167,7 @@ describe('getDevServerConfig', () => {
});
it('should open the url if --open is passed', () => {
mockServer.options.open = true;
serveInput.open = true;
const { devServer: result } = getDevServerConfig(
root,
sourceRoot,

View File

@ -67,7 +67,7 @@ function getDevServerPartial(
});
logger.info(`NX Web Development Server is listening at ${serverUrl}`);
if (server.options.open) {
if (options.open) {
opn(serverUrl, {
wait: false,
});

View File

@ -1,13 +1,12 @@
import { normalizeBuildOptions, normalizePackageOptions } from './normalize';
import { BuildBuilderOptions, PackageBuilderOptions } from './types';
import { Path, normalize } from '@angular-devkit/core';
import * as fs from 'fs';
describe('normalizeBuildOptions', () => {
let testOptions: BuildBuilderOptions;
let root: string;
let sourceRoot: Path;
let sourceRoot: string;
beforeEach(() => {
testOptions = {
@ -29,7 +28,7 @@ describe('normalizeBuildOptions', () => {
webpackConfig: 'apps/nodeapp/webpack.config',
};
root = '/root';
sourceRoot = normalize('apps/nodeapp/src');
sourceRoot = 'apps/nodeapp/src';
});
it('should resolve main from root', () => {
@ -117,7 +116,7 @@ describe('normalizeBuildOptions', () => {
describe('normalizePackageOptions', () => {
let testOptions: PackageBuilderOptions;
let root: string;
let sourceRoot: Path;
let sourceRoot: string;
beforeEach(() => {
testOptions = {
@ -129,7 +128,7 @@ describe('normalizePackageOptions', () => {
rollupConfig: 'apps/nodeapp/rollup.config',
};
root = '/root';
sourceRoot = normalize('apps/nodeapp/src');
sourceRoot = 'apps/nodeapp/src';
});
it('should resolve both node modules and relative path for babelConfig/rollupConfig', () => {

View File

@ -1,13 +0,0 @@
import { BuilderContext } from '@angular-devkit/architect';
export async function getSourceRoot(context: BuilderContext): Promise<string> {
const projectMeta = await context.getProjectMetadata(context.target.project);
if (projectMeta.sourceRoot) {
return projectMeta.sourceRoot as string;
} else {
context.reportStatus('Error');
const message = `${context.target.project} does not have a sourceRoot. Please define one.`;
context.logger.error(message);
throw new Error(message);
}
}

View File

@ -1,56 +0,0 @@
import { join } from 'path';
import { schema } from '@angular-devkit/core';
import { Rule, Tree } from '@angular-devkit/schematics';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import { Architect } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { MockBuilderContext } from '@nrwl/workspace/testing';
const testRunner = new SchematicTestRunner(
'@nrwl/web',
join(__dirname, '../../collection.json')
);
testRunner.registerCollection(
'@nrwl/jest',
join(__dirname, '../../../jest/collection.json')
);
testRunner.registerCollection(
'@nrwl/cypress',
join(__dirname, '../../../cypress/collection.json')
);
export function runSchematic<T = any>(
schematicName: string,
options: T,
tree: Tree
) {
return testRunner.runSchematicAsync(schematicName, options, tree).toPromise();
}
export function callRule(rule: Rule, tree: Tree) {
return testRunner.callRule(rule, tree).toPromise();
}
export async function getTestArchitect() {
const architectHost = new TestingArchitectHost('/root', '/root');
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
const architect = new Architect(architectHost, registry);
await architectHost.addBuilderFromPackage(join(__dirname, '../..'));
return [architect, architectHost] as [Architect, TestingArchitectHost];
}
export async function getMockContext() {
const [architect, architectHost] = await getTestArchitect();
const context = new MockBuilderContext(architect, architectHost);
await context.addBuilderFromPackage(join(__dirname, '../..'));
return context;
}

View File

@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`augment-index-html can generate index.html 1`] = `"<html><head><base href=\\"/\\"><link rel=\\"stylesheet\\" href=\\"styles.css\\"></head><body><script src=\\"runtime.js\\" defer></script><script src=\\"polyfills.js\\" defer></script><script src=\\"main.js\\" defer></script></body></html>"`;
exports[`augment-index-html should emit correct script tags when having 'module' and 'non-module' js 1`] = `"<html><head><base href=\\"/\\"><link rel=\\"stylesheet\\" href=\\"styles.css\\"></head><body><script src=\\"runtime-es2015.js\\" type=\\"module\\"></script><script src=\\"polyfills-es2015.js\\" type=\\"module\\"></script><script src=\\"runtime-es5.js\\" nomodule defer></script><script src=\\"polyfills-es5.js\\" nomodule defer></script><script src=\\"main-es2015.js\\" type=\\"module\\"></script><script src=\\"main-es5.js\\" nomodule defer></script></body></html>"`;
exports[`augment-index-html should not add 'module' and 'non-module' attr to js files which are in both module formats 1`] = `"<html><head><base href=\\"/\\"><link rel=\\"stylesheet\\" href=\\"styles.css\\"></head><body><script src=\\"scripts.js\\" defer></script><script src=\\"main-es2015.js\\" type=\\"module\\"></script><script src=\\"main-es5.js\\" nomodule defer></script></body></html>"`;

View File

@ -5,7 +5,6 @@
* 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 { tags } from '@angular-devkit/core';
import {
AugmentIndexHtmlOptions,
FileInfo,
@ -19,13 +18,10 @@ describe('augment-index-html', () => {
baseHref: '/',
sri: false,
files: [],
loadOutputFile: async (_fileName: string) => '',
loadOutputFile: (_fileName: string) => '',
entrypoints: ['scripts', 'polyfills', 'main', 'styles'],
};
const oneLineHtml = (html: TemplateStringsArray) =>
tags.stripIndents`${html}`.replace(/(\>\s+)/g, '>');
it('can generate index.html', async () => {
const source = augmentIndexHtml({
...indexGeneratorOptions,
@ -39,18 +35,7 @@ describe('augment-index-html', () => {
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<html>
<head><base href="/">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="runtime.js" defer></script>
<script src="polyfills.js" defer></script>
<script src="main.js" defer></script>
</body>
</html>
`);
expect(html).toMatchSnapshot();
});
it(`should emit correct script tags when having 'module' and 'non-module' js`, async () => {
@ -79,22 +64,7 @@ describe('augment-index-html', () => {
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<html>
<head>
<base href="/">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="runtime-es2015.js" type="module"></script>
<script src="polyfills-es2015.js" type="module"></script>
<script src="runtime-es5.js" nomodule defer></script>
<script src="polyfills-es5.js" nomodule defer></script>
<script src="main-es2015.js" type="module"></script>
<script src="main-es5.js" nomodule defer></script>
</body>
</html>
`);
expect(html).toMatchSnapshot();
});
it(`should not add 'module' and 'non-module' attr to js files which are in both module formats`, async () => {
@ -119,18 +89,6 @@ describe('augment-index-html', () => {
});
const html = await source;
expect(html).toEqual(oneLineHtml`
<html>
<head>
<base href="/">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<script src="scripts.js" defer></script>
<script src="main-es2015.js" type="module"></script>
<script src="main-es5.js" nomodule defer></script>
</body>
</html>
`);
expect(html).toMatchSnapshot();
});
});

View File

@ -6,72 +6,61 @@
* found in the LICENSE file at https://angular.io/license
*/
import { TestProjectHost } from '@angular-devkit/architect/testing';
import { getSystemPath, join } from '@angular-devkit/core';
import { fs, vol } from 'memfs';
jest.mock('fs', () => fs);
import { ScriptTarget } from 'typescript';
// Disable browserslist cache so that each test resolves a new config.
process.env.BROWSERSLIST_DISABLE_CACHE = 'true';
import { BuildBrowserFeatures } from './build-browser-features';
const devkitRoot = (global as any)._DevKitRoot; // tslint:disable-line:no-any
const workspaceRoot = join(
devkitRoot,
'tests/angular_devkit/build_angular/hello-world-app/'
);
const host = new TestProjectHost(workspaceRoot);
describe('BuildBrowserFeatures', () => {
let workspaceRootSysPath = '';
beforeEach(async () => {
await host.initialize().toPromise();
workspaceRootSysPath = getSystemPath(host.root());
vol.fromJSON(
{
'.browserslistrc': '',
},
'/root'
);
});
afterEach(async () => host.restore().toPromise());
describe('isDifferentialLoadingNeeded', () => {
it('should be true for for IE 9-11 and ES2015', () => {
host.writeMultipleFiles({
browserslist: 'IE 9-11',
});
fs.writeFileSync('/root/.browserslistrc', 'IE 9-11');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(true);
});
it('should be false for Chrome and ES2015', () => {
host.writeMultipleFiles({
browserslist: 'last 1 chrome version',
});
fs.writeFileSync('/root/.browserslistrc', 'last 1 chrome version');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
});
it('detects no need for differential loading for target is ES5', () => {
host.writeMultipleFiles({
browserslist: 'last 1 chrome version',
});
fs.writeFileSync('/root/.browserslistrc', 'last 1 chrome version');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES5
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
});
it('should be false for Safari 10.1 when target is ES2015', () => {
host.writeMultipleFiles({
browserslist: 'Safari 10.1',
});
fs.writeFileSync('/root/.browserslistrc', 'Safari 10.1');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isDifferentialLoadingNeeded()).toBe(false);
@ -80,48 +69,40 @@ describe('BuildBrowserFeatures', () => {
describe('isFeatureSupported', () => {
it('should be true for es6-module and Safari 10.1', () => {
host.writeMultipleFiles({
browserslist: 'Safari 10.1',
});
fs.writeFileSync('/root/.browserslistrc', 'Safari 10.1');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
it('should be false for es6-module and IE9', () => {
host.writeMultipleFiles({
browserslist: 'IE 9',
});
fs.writeFileSync('/root/.browserslistrc', 'IE 9');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(false);
});
it('should be true for es6-module and last 1 chrome version', () => {
host.writeMultipleFiles({
browserslist: 'last 1 chrome version',
});
fs.writeFileSync('/root/.browserslistrc', 'last 1 chrome version');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
});
it('should be true for es6-module and Edge 18', () => {
host.writeMultipleFiles({
browserslist: 'Edge 18',
});
fs.writeFileSync('/root/.browserslistrc', 'Edge 18');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isFeatureSupported('es6-module')).toBe(true);
@ -130,63 +111,56 @@ describe('BuildBrowserFeatures', () => {
describe('isNoModulePolyfillNeeded', () => {
it('should be false for Safari 10.1 when target is ES5', () => {
host.writeMultipleFiles({
browserslist: 'Safari 10.1',
});
fs.writeFileSync('/root/.browserslistrc', 'Safari 10.1');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES5
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
it('should be false for Safari 10.1 when target is ES2015', () => {
host.writeMultipleFiles({
browserslist: 'Safari 10.1',
});
fs.writeFileSync('/root/.browserslistrc', 'Safari 10.1');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
it('should be true for Safari 9+ when target is ES2015', () => {
host.writeMultipleFiles({
browserslist: 'Safari >= 9',
});
fs.writeFileSync('/root/.browserslistrc', 'Safari >= 9');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(true);
});
it('should be false for Safari 9+ when target is ES5', () => {
host.writeMultipleFiles({
browserslist: 'Safari >= 9',
});
fs.writeFileSync('/root/.browserslistrc', 'Safari >= 9');
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES5
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);
});
it('should be false when not supporting Safari 10.1 target is ES2015', () => {
host.writeMultipleFiles({
browserslist: `
Edge 18
IE 9
`,
});
fs.writeFileSync(
'/root/.browserslistrc',
`
Edge 18
IE 9
`
);
const buildBrowserFeatures = new BuildBrowserFeatures(
workspaceRootSysPath,
'/root',
ScriptTarget.ES2015
);
expect(buildBrowserFeatures.isNoModulePolyfillNeeded()).toBe(false);