Skip to content

Commit

Permalink
feat(web): update Next.js, Web, and Node generators to not use Babel …
Browse files Browse the repository at this point in the history
…by default

Note: React still needs Babel by default if using styled-components or
emotion. Will address it in a separate PR.
  • Loading branch information
jaysoo committed May 29, 2023
1 parent f01cdca commit 04135ff
Show file tree
Hide file tree
Showing 32 changed files with 52 additions and 156 deletions.
5 changes: 0 additions & 5 deletions docs/generated/packages/express/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
"type": "string",
"description": "Frontend project that needs to access this application. This sets up proxy configuration."
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/jest/generators/jest-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"compiler": {
"type": "string",
"enum": ["tsc", "babel", "swc"],
"enum": ["tsc", "swc", "babel"],
"description": "The compiler to use for source and tests.",
"default": "tsc"
},
Expand Down
5 changes: 0 additions & 5 deletions docs/generated/packages/node/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
"description": "Frontend project that needs to access this application. This sets up proxy configuration.",
"x-priority": "important"
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
Expand Down
5 changes: 0 additions & 5 deletions docs/generated/packages/node/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@
"description": "The test environment to use if `unitTestRunner` is set to `jest`.",
"default": "jsdom"
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
Expand Down
6 changes: 3 additions & 3 deletions docs/generated/packages/react/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
"default": false,
"x-priority": "internal"
},
"skipWorkspaceJson": {
"description": "Skip updating `workspace.json` with default options based on values provided to this app (e.g. babel, style).",
"skipNxJson": {
"description": "Skip updating `nx.json` with default options based on values provided to this app.",
"type": "boolean",
"default": false,
"x-priority": "internal"
Expand Down Expand Up @@ -155,7 +155,7 @@
"compiler": {
"type": "string",
"description": "The compiler to use.",
"enum": ["babel", "swc"],
"enum": ["swc", "babel"],
"default": "babel"
},
"skipPackageJson": {
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/react/generators/host.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"default": false,
"x-priority": "internal"
},
"skipWorkspaceJson": {
"skipNxJson": {
"description": "Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).",
"type": "boolean",
"default": false,
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/react/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
},
"compiler": {
"type": "string",
"enum": ["babel", "swc"],
"enum": ["swc", "babel"],
"default": "babel",
"description": "Which compiler to use. Only applies to `bundler: 'rollup'`."
},
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/react/generators/remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"default": false,
"x-priority": "internal"
},
"skipWorkspaceJson": {
"skipNxJson": {
"description": "Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).",
"type": "boolean",
"default": false,
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/packages/web/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"compiler": {
"type": "string",
"description": "The compiler to use",
"enum": ["babel", "swc"],
"default": "babel",
"enum": ["swc", "babel"],
"default": "swc",
"x-priority": "important"
},
"bundler": {
Expand Down
1 change: 0 additions & 1 deletion packages/express/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface Schema {
tags?: string;
linter: Linter;
frontendProject?: string;
babelJest?: boolean;
js: boolean;
pascalCaseFiles: boolean;
standaloneConfig?: boolean;
Expand Down
5 changes: 0 additions & 5 deletions packages/express/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
"type": "string",
"description": "Frontend project that needs to access this application. This sets up proxy configuration."
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/src/generators/jest-project/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"compiler": {
"type": "string",
"enum": ["tsc", "babel", "swc"],
"enum": ["tsc", "swc", "babel"],
"description": "The compiler to use for source and tests.",
"default": "tsc"
},
Expand Down
30 changes: 0 additions & 30 deletions packages/next/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,6 @@ export async function libraryGenerator(host: Tree, rawOptions: Schema) {
);
addTsConfigPath(host, `${options.importPath}/server`, [serverEntryPath]);

updateJson(
host,
joinPathFragments(options.projectRoot, '.babelrc'),
(json) => {
if (options.style === '@emotion/styled') {
json.presets = [
[
'@nx/next/babel',
{
'preset-react': {
runtime: 'automatic',
importSource: '@emotion/react',
},
},
],
];
} else if (options.style === 'styled-jsx') {
// next.js doesn't require the `styled-jsx/babel' plugin as it is already
// built-into the `next/babel` preset
json.presets = ['@nx/next/babel'];
json.plugins = (json.plugins || []).filter(
(x) => x !== 'styled-jsx/babel'
);
} else {
json.presets = ['@nx/next/babel'];
}
return json;
}
);

updateJson(
host,
joinPathFragments(options.projectRoot, 'tsconfig.json'),
Expand Down
25 changes: 0 additions & 25 deletions packages/node/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,31 +343,6 @@ describe('app', () => {
});
});

describe('--babelJest', () => {
it('should use babel for jest', async () => {
await applicationGenerator(tree, {
name: 'myNodeApp',
tags: 'one,two',
babelJest: true,
} as Schema);

expect(tree.read(`my-node-app/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"/* eslint-disable */
export default {
displayName: 'my-node-app',
preset: '../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\\\.[tj]s$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../coverage/my-node-app',
};
"
`);
});
});
describe('--js flag', () => {
it('should generate js files instead of ts files', async () => {
await applicationGenerator(tree, {
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface Schema {
linter?: Linter;
tags?: string;
frontendProject?: string;
babelJest?: boolean;
js?: boolean;
pascalCaseFiles?: boolean;
setParserOptionsProject?: boolean;
Expand Down
5 changes: 0 additions & 5 deletions packages/node/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
"description": "Frontend project that needs to access this application. This sets up proxy configuration.",
"x-priority": "important"
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
Expand Down
24 changes: 0 additions & 24 deletions packages/node/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,30 +448,6 @@ describe('lib', () => {
});
});

describe(`--babelJest`, () => {
it('should use babel for jest', async () => {
await libraryGenerator(tree, {
name: 'myLib',
babelJest: true,
} as Schema);

expect(tree.read(`libs/my-lib/jest.config.ts`, 'utf-8'))
.toMatchInlineSnapshot(`
"/* eslint-disable */
export default {
displayName: 'my-lib',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\\\.[tj]s$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/my-lib',
};
"
`);
});
});
describe('--js flag', () => {
it('should generate js files instead of ts files', async () => {
await libraryGenerator(tree, {
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/generators/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function libraryGenerator(tree: Tree, schema: Schema) {
const libraryInstall = await jsLibraryGenerator(tree, {
...schema,
bundler: schema.buildable ? 'tsc' : 'none',
includeBabelRc: schema.babelJest,
importPath: options.importPath,
testEnvironment: 'node',
skipFormat: true,
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/generators/library/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface Schema {
importPath?: string;
testEnvironment?: 'jsdom' | 'node';
rootDir?: string;
babelJest?: boolean;
js?: boolean;
pascalCaseFiles?: boolean;
strict?: boolean;
Expand Down
5 changes: 0 additions & 5 deletions packages/node/src/generators/library/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@
"description": "The test environment to use if `unitTestRunner` is set to `jest`.",
"default": "jsdom"
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"default": false
},
"pascalCaseFiles": {
"type": "boolean",
"description": "Use pascal case file names.",
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,12 +849,12 @@ describe('app', () => {
).toBeUndefined();
});

describe('--skipWorkspaceJson', () => {
describe('--skipNxJson', () => {
it('should update workspace with defaults when --skipprojectsConfigurations=false', async () => {
await applicationGenerator(appTree, {
...schema,
style: 'styled-components',
skipWorkspaceJson: false,
skipNxJson: false,
});

const nxJson = readNxJson(appTree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readNxJson, Tree, updateNxJson } from '@nx/devkit';
import { NormalizedSchema } from '../schema';

export function setDefaults(host: Tree, options: NormalizedSchema) {
if (options.skipWorkspaceJson) {
if (options.skipNxJson) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Schema {
pascalCaseFiles?: boolean;
classComponent?: boolean;
routing?: boolean;
skipWorkspaceJson?: boolean;
skipNxJson?: boolean;
js?: boolean;
globalCss?: boolean;
strict?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"default": false,
"x-priority": "internal"
},
"skipWorkspaceJson": {
"description": "Skip updating `workspace.json` with default options based on values provided to this app (e.g. babel, style).",
"skipNxJson": {
"description": "Skip updating `nx.json` with default options based on values provided to this app.",
"type": "boolean",
"default": false,
"x-priority": "internal"
Expand Down Expand Up @@ -161,7 +161,7 @@
"compiler": {
"type": "string",
"description": "The compiler to use.",
"enum": ["babel", "swc"],
"enum": ["swc", "babel"],
"default": "babel"
},
"skipPackageJson": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/host/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Schema {
remotes?: string[];
setParserOptionsProject?: boolean;
skipFormat?: boolean;
skipWorkspaceJson?: boolean;
skipNxJson?: boolean;
ssr?: boolean;
strict?: boolean;
style: SupportedStyles;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/host/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"default": false,
"x-priority": "internal"
},
"skipWorkspaceJson": {
"skipNxJson": {
"description": "Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).",
"type": "boolean",
"default": false,
Expand Down

This file was deleted.

Loading

0 comments on commit 04135ff

Please sign in to comment.