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
  • Loading branch information
jaysoo committed May 29, 2023
1 parent 923e6d8 commit 5db0408
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 142 deletions.
8 changes: 7 additions & 1 deletion docs/generated/packages/express/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@
"type": "string",
"description": "Frontend project that needs to access this application. This sets up proxy configuration."
},
"swcJest": {
"type": "boolean",
"description": "Use `@swc/jest` instead `ts-jest` for faster test compilation.",
"default": false
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead `ts-jest`.",
"default": false
"default": false,
"x-deprecated": "Use --swcJest instead for faster compilation"
},
"pascalCaseFiles": {
"type": "boolean",
Expand Down
10 changes: 8 additions & 2 deletions docs/generated/packages/node/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@
"description": "Frontend project that needs to access this application. This sets up proxy configuration.",
"x-priority": "important"
},
"babelJest": {
"swcJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"description": "Use `@swc/jest` instead `ts-jest` for faster test compilation.",
"default": false
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead `ts-jest`.",
"default": false,
"x-deprecated": "Use --swcJest instead for faster compilation"
},
"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
4 changes: 2 additions & 2 deletions e2e/web/src/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Web Components Applications', () => {
runCLI(`build ${appName} --outputHashing none`);

expect(readFile(`dist/apps/${appName}/main.js`)).toMatch(
/Reflect\.metadata/
/Foo=__decorate\(\[sealed\],Foo\)/
);

// Turn off decorator metadata
Expand All @@ -151,7 +151,7 @@ describe('Web Components Applications', () => {
runCLI(`build ${appName} --outputHashing none`);

expect(readFile(`dist/apps/${appName}/main.js`)).not.toMatch(
/Reflect\.metadata/
/Foo=__decorate\(\[sealed\],Foo\)/
);
}, 120000);

Expand Down
2 changes: 2 additions & 0 deletions packages/express/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface Schema {
tags?: string;
linter: Linter;
frontendProject?: string;
swcJest?: boolean;
/** @deprecated use `swcJest` instead */
babelJest?: boolean;
js: boolean;
pascalCaseFiles: boolean;
Expand Down
8 changes: 7 additions & 1 deletion packages/express/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@
"type": "string",
"description": "Frontend project that needs to access this application. This sets up proxy configuration."
},
"swcJest": {
"type": "boolean",
"description": "Use `@swc/jest` instead `ts-jest` for faster test compilation.",
"default": false
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead `ts-jest`.",
"default": false
"default": false,
"x-deprecated": "Use --swcJest instead for faster compilation"
},
"pascalCaseFiles": {
"type": "boolean",
Expand Down
61 changes: 0 additions & 61 deletions packages/next/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,6 @@ describe('next library', () => {
let mockedInstalledCypressVersion: jest.Mock<
ReturnType<typeof installedCypressVersion>
> = installedCypressVersion as never;
it('should use "@nx/next/babel" preset in babelrc', async () => {
const baseOptions: Schema = {
name: '',
linter: Linter.EsLint,
skipFormat: false,
skipTsConfig: false,
unitTestRunner: 'jest',
style: 'css',
component: true,
};

const appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

await libraryGenerator(appTree, {
...baseOptions,
name: 'myLib',
});
await libraryGenerator(appTree, {
...baseOptions,
name: 'myLib2',
style: '@emotion/styled',
});
await libraryGenerator(appTree, {
...baseOptions,
name: 'myLib-styled-jsx',
style: 'styled-jsx',
});
await libraryGenerator(appTree, {
...baseOptions,
name: 'myLib3',
directory: 'myDir',
});

expect(readJson(appTree, 'libs/my-lib/.babelrc')).toEqual({
presets: ['@nx/next/babel'],
plugins: [],
});
expect(readJson(appTree, 'libs/my-lib2/.babelrc')).toEqual({
presets: [
[
'@nx/next/babel',
{
'preset-react': {
runtime: 'automatic',
importSource: '@emotion/react',
},
},
],
],
plugins: ['@emotion/babel-plugin'],
});
expect(readJson(appTree, 'libs/my-lib-styled-jsx/.babelrc')).toEqual({
presets: ['@nx/next/babel'],
plugins: [],
});
expect(readJson(appTree, 'libs/my-dir/my-lib3/.babelrc')).toEqual({
presets: ['@nx/next/babel'],
plugins: [],
});
});

it('should use @nx/next images.d.ts file', async () => {
const baseOptions: Schema = {
name: '',
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
29 changes: 28 additions & 1 deletion packages/node/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,33 @@ describe('app', () => {
});
});

describe('--babelJest', () => {
describe('--swcJjest', () => {
it('should use @swc/jest for jest', async () => {
await applicationGenerator(tree, {
name: 'myNodeApp',
tags: 'one,two',
swcJest: 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$': '@swc/jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../coverage/my-node-app',
};
"
`);
});
});

describe('--babelJest (deprecated)', () => {
it('should use babel for jest', async () => {
await applicationGenerator(tree, {
name: 'myNodeApp',
Expand All @@ -368,6 +394,7 @@ describe('app', () => {
`);
});
});

describe('--js flag', () => {
it('should generate js files instead of ts files', async () => {
await applicationGenerator(tree, {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) {
skipSerializers: true,
supportTsx: options.js,
testEnvironment: 'node',
compiler: 'tsc',
compiler: options.swcJest ? 'swc' : 'tsc',
skipFormat: true,
});
tasks.push(jestTask);
Expand Down
2 changes: 2 additions & 0 deletions packages/node/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface Schema {
linter?: Linter;
tags?: string;
frontendProject?: string;
swcJest?: boolean;
/** @deprecated use `swcJest` instead */
babelJest?: boolean;
js?: boolean;
pascalCaseFiles?: boolean;
Expand Down
10 changes: 8 additions & 2 deletions packages/node/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@
"description": "Frontend project that needs to access this application. This sets up proxy configuration.",
"x-priority": "important"
},
"babelJest": {
"swcJest": {
"type": "boolean",
"description": "Use `babel` instead of `ts-jest`.",
"description": "Use `@swc/jest` instead `ts-jest` for faster test compilation.",
"default": false
},
"babelJest": {
"type": "boolean",
"description": "Use `babel` instead `ts-jest`.",
"default": false,
"x-deprecated": "Use --swcJest instead for faster compilation"
},
"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
Loading

0 comments on commit 5db0408

Please sign in to comment.