Skip to content

Commit

Permalink
feat(nest): rename tsPlugins to transformers and add tsPlugins to ali…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
Chau Tran authored and Chau Tran committed Mar 2, 2022
1 parent 71278bc commit 70ab825
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 39 deletions.
2 changes: 2 additions & 0 deletions docs/generated/api-nest/generators/library.md
Expand Up @@ -135,6 +135,8 @@ Do not update tsconfig.base.json for development experience.

### standaloneConfig

Default: `true`

Type: `boolean`

Split the project configuration into <projectRoot>/project.json rather than including it inside workspace.json
Expand Down
6 changes: 4 additions & 2 deletions docs/generated/api-node/executors/webpack.md
Expand Up @@ -159,11 +159,13 @@ Type: `boolean`

Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or <https://webpack.github.io/analyse>.

### tsPlugins
### transformers

Alias(es): tsPlugins

Type: `array`

List of TypeScript Compiler Plugins.
List of TypeScript Compiler Transfomers Plugins.

### verbose

Expand Down
23 changes: 11 additions & 12 deletions e2e/utils/index.ts
@@ -1,4 +1,12 @@
import {
joinPathFragments,
parseJson,
ProjectConfiguration,
WorkspaceJsonConfiguration,
} from '@nrwl/devkit';
import { detectPackageManager } from '@nrwl/tao/src/shared/package-manager';
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
import { angularCliVersion } from '@nrwl/workspace/src/utils/versions';
import { ChildProcess, exec, execSync } from 'child_process';
import {
copySync,
Expand All @@ -14,21 +22,12 @@ import {
} from 'fs-extra';
import * as path from 'path';
import { join } from 'path';
import { dirSync } from 'tmp';
import { coerce } from 'semver';
import { check as portCheck } from 'tcp-port-used';
import {
joinPathFragments,
parseJson,
ProjectConfiguration,
WorkspaceJsonConfiguration,
} from '@nrwl/devkit';
import { dirSync } from 'tmp';
import { promisify } from 'util';
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
import { angularCliVersion } from '@nrwl/workspace/src/utils/versions';
import { coerce } from 'semver';
import isCI = require('is-ci');

import chalk = require('chalk');
import isCI = require('is-ci');
import treeKill = require('tree-kill');

const kill = require('kill-port');
Expand Down
9 changes: 5 additions & 4 deletions packages/node/src/executors/webpack/schema.json
Expand Up @@ -131,12 +131,13 @@
"description": "Generates a package.json file with the project's node_module dependencies populated for installing in a container. If a package.json exists in the project's directory, it will be reused with dependencies populated.",
"default": false
},
"tsPlugins": {
"transformers": {
"type": "array",
"description": "List of TypeScript Compiler Plugins.",
"description": "List of TypeScript Compiler Transfomers Plugins.",
"default": [],
"aliases": ["tsPlugins"],
"items": {
"$ref": "#/definitions/tsPluginPattern"
"$ref": "#/definitions/transformerPattern"
}
},
"additionalEntryPoints": {
Expand Down Expand Up @@ -196,7 +197,7 @@
}
]
},
"tsPluginPattern": {
"transformerPattern": {
"oneOf": [
{
"type": "string"
Expand Down
15 changes: 8 additions & 7 deletions packages/node/src/utils/config.ts
@@ -1,14 +1,13 @@
import { readTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
import * as ts from 'typescript';
import type { Configuration, WebpackPluginInstance } from 'webpack';
import * as webpack from 'webpack';
import * as ts from 'typescript';
import { LicenseWebpackPlugin } from 'license-webpack-plugin';

import { readTsConfig } from '@nrwl/workspace/src/utilities/typescript';
import { loadTsTransformers } from './load-ts-transformers';
import { BuildBuilderOptions } from './types';
import { loadTsPlugins } from './load-ts-plugins';
import CopyWebpackPlugin = require('copy-webpack-plugin');
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';

export const OUT_FILENAME_TEMPLATE = '[name].js';

Expand All @@ -22,7 +21,9 @@ export function getBaseWebpackPartial(
const mainFields = [...(supportsEs2015 ? ['es2015'] : []), 'module', 'main'];
const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];

const { compilerPluginHooks, hasPlugin } = loadTsPlugins(options.tsPlugins);
const { compilerPluginHooks, hasPlugin } = loadTsTransformers(
options.transformers
);

const additionalEntryPoints =
options.additionalEntryPoints?.reduce(
Expand Down
@@ -1,22 +1,22 @@
import { loadTsPlugins } from './load-ts-plugins';
import { loadTsTransformers } from './load-ts-transformers';

jest.mock('plugin-a');
jest.mock('plugin-b');
const mockRequireResolve = jest.fn((path) => path);

describe('loadTsPlugins', () => {
describe('loadTsTransformers', () => {
it('should return empty hooks if plugins is falsy', () => {
const result = loadTsPlugins(undefined);
const result = loadTsTransformers(undefined);
assertEmptyResult(result);
});

it('should return empty hooks if plugins is []', () => {
const result = loadTsPlugins([]);
const result = loadTsTransformers([]);
assertEmptyResult(result);
});

it('should return correct compiler hooks', () => {
const result = loadTsPlugins(
const result = loadTsTransformers(
['plugin-a', 'plugin-b'],
mockRequireResolve as any
);
Expand All @@ -29,7 +29,7 @@ describe('loadTsPlugins', () => {
});
});

function assertEmptyResult(result: ReturnType<typeof loadTsPlugins>) {
function assertEmptyResult(result: ReturnType<typeof loadTsTransformers>) {
expect(result.hasPlugin).toEqual(false);
expect(result.compilerPluginHooks).toEqual({
beforeHooks: [],
Expand Down
Expand Up @@ -3,12 +3,12 @@ import { join } from 'path';
import {
CompilerPlugin,
CompilerPluginHooks,
TsPlugin,
TsPluginEntry,
TransformerEntry,
TransformerPlugin,
} from './types';

export function loadTsPlugins(
plugins: TsPluginEntry[],
export function loadTsTransformers(
plugins: TransformerEntry[],
moduleResolver: typeof require.resolve = require.resolve
): {
compilerPluginHooks: CompilerPluginHooks;
Expand All @@ -29,7 +29,7 @@ export function loadTsPlugins(
hasPlugin: false,
};

const normalizedPlugins: TsPlugin[] = plugins.map((plugin) =>
const normalizedPlugins: TransformerPlugin[] = plugins.map((plugin) =>
typeof plugin === 'string' ? { name: plugin, options: {} } : plugin
);

Expand Down
6 changes: 3 additions & 3 deletions packages/node/src/utils/types.ts
Expand Up @@ -26,12 +26,12 @@ type TransformerFactory =
| TypescriptTransformerFactory<Node>
| CustomTransformerFactory;

export interface TsPlugin {
export interface TransformerPlugin {
name: string;
options: Record<string, unknown>;
}

export type TsPluginEntry = string | TsPlugin;
export type TransformerEntry = string | TransformerPlugin;

export interface CompilerPlugin {
before?: (
Expand Down Expand Up @@ -84,7 +84,7 @@ export interface BuildBuilderOptions {
sourceRoot?: string;
projectRoot?: string;

tsPlugins?: TsPluginEntry[];
transformers?: TransformerEntry[];

additionalEntryPoints?: AdditionalEntryPoint[];
outputFileName?: string;
Expand Down

0 comments on commit 70ab825

Please sign in to comment.