Skip to content

Commit

Permalink
Merge branch 'master' into feat/nextjs-cli-default
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham authored and jaysoo committed May 16, 2023
2 parents 7a855f6 + cac64d7 commit eb2feee
Show file tree
Hide file tree
Showing 47 changed files with 218 additions and 245 deletions.
1 change: 0 additions & 1 deletion e2e/next/src/next-appdir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { getData } from 'ajv/dist/compile/validate';
import { detectPackageManager } from 'nx/src/utils/package-manager';
import { checkApp } from './utils';
import { p } from 'vitest/dist/types-b7007192';

describe('Next.js App Router', () => {
let proj: string;
Expand Down
3 changes: 0 additions & 3 deletions e2e/next/src/next-storybook.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {
checkFilesExist,
cleanupProject,
getPackageManagerCommand,
newProject,
runCLI,
runCommand,
uniq,
updateJson,
} from '@nx/e2e/utils';

describe('Next.js Applications', () => {
Expand Down
6 changes: 3 additions & 3 deletions e2e/next/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
checkFilesExist,
killPorts,
killPort,
readJson,
runCLI,
runCLIAsync,
Expand Down Expand Up @@ -42,10 +42,10 @@ export async function checkApp(

if (opts.checkE2E && runCypressTests()) {
const e2eResults = runCLI(
`e2e ${appName}-e2e --no-watch --configuration=production`
`e2e ${appName}-e2e --no-watch --configuration=production --port=5000`
);
expect(e2eResults).toContain('All specs passed!');
expect(await killPorts()).toBeTruthy();
expect(await killPort(5000)).toBeTruthy();
}

if (opts.checkExport) {
Expand Down
13 changes: 3 additions & 10 deletions packages/angular/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import path = require('path');
import json = require('./migrations.json');
import { MigrationsJsonEntry } from 'nx/src/config/misc-interfaces';

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';

describe('Angular migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: MigrationsJsonEntry) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
assertValidMigrationPaths(json, __dirname);
});
13 changes: 3 additions & 10 deletions packages/cypress/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import path = require('path');
import json = require('./migrations.json');

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';

describe('Cypress migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators || {}).forEach((m: any) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
assertValidMigrationPaths(json, __dirname);
});
13 changes: 3 additions & 10 deletions packages/detox/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import path = require('path');
import json = require('./migrations.json');

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';

describe('Detox migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: any) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
assertValidMigrationPaths(json, __dirname);
});
3 changes: 3 additions & 0 deletions packages/devkit/internal-testing-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */
export * from 'nx/internal-testing-utils/assert-valid-migrations';
export * from 'nx/internal-testing-utils/run-migration-against-this-workspace';
7 changes: 7 additions & 0 deletions packages/devkit/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import json = require('./migrations.json');

import { assertValidMigrationPaths } from './internal-testing-utils';

describe('Devkit migrations', () => {
assertValidMigrationPaths(json, __dirname);
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assertRunsAgainstNxRepo } from 'nx/internal-testing-utils/run-migration-against-this-workspace';
import { createTreeWithEmptyWorkspace } from 'nx/src/generators/testing-utils/create-tree-with-empty-workspace';
import { Tree } from 'nx/src/generators/tree';
import { readJson, updateJson } from 'nx/src/generators/utils/json';
Expand Down Expand Up @@ -35,4 +36,6 @@ describe('update-16-0-0-add-nx-packages', () => {

expect(newDependencyVersion).toBeDefined();
});

assertRunsAgainstNxRepo(replacePackage);
});
1 change: 1 addition & 0 deletions packages/devkit/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"**/*.test.ts",
"**/*_spec.ts",
"**/*_test.ts",
"internal-testing-utils.ts",
"jest.config.ts"
],
"files": ["./index.d.ts"],
Expand Down
1 change: 1 addition & 0 deletions packages/devkit/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"**/*.spec.jsx",
"**/*.test.jsx",
"**/*.d.ts",
"internal-testing-utils.ts",
"jest.config.ts"
]
}
13 changes: 3 additions & 10 deletions packages/esbuild/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import path = require('path');
import json = require('./migrations.json');

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';

describe('esbuild migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: any) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
assertValidMigrationPaths(json, __dirname);
});
7 changes: 7 additions & 0 deletions packages/eslint-plugin/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import json = require('./migrations.json');

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';

describe('eslint-plugin migrations', () => {
assertValidMigrationPaths(json, __dirname);
});
8 changes: 8 additions & 0 deletions packages/expo/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import json = require('./migrations.json');

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('expo migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
16 changes: 5 additions & 11 deletions packages/express/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import path = require('path');
import json = require('./migrations.json');

describe('Express migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: any) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('express migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
17 changes: 5 additions & 12 deletions packages/jest/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import path = require('path');
import json = require('./migrations.json');
import { MigrationsJsonEntry } from 'nx/src/config/misc-interfaces';

describe('Jest migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: MigrationsJsonEntry) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('jest migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
16 changes: 5 additions & 11 deletions packages/js/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import path = require('path');
import json = require('./migrations.json');

describe('JS migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: any) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('js migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
17 changes: 5 additions & 12 deletions packages/linter/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import path = require('path');
import json = require('./migrations.json');
import { MigrationsJsonEntry } from 'nx/src/config/misc-interfaces';

describe('Linter migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: MigrationsJsonEntry) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('linter migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
17 changes: 5 additions & 12 deletions packages/nest/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import path = require('path');
import json = require('./migrations.json');
import { MigrationsJsonEntry } from 'nx/src/config/misc-interfaces';

describe('Nest migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: MigrationsJsonEntry) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('nest migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
17 changes: 5 additions & 12 deletions packages/next/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import path = require('path');
import json = require('./migrations.json');
import { MigrationsJsonEntry } from 'nx/src/config/misc-interfaces';

describe('Next migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: MigrationsJsonEntry) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('next migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
14 changes: 4 additions & 10 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dotenv/config';
import * as net from 'net';
import {
ExecutorContext,
logger,
parseTargetString,
readTargetOptions,
} from '@nx/devkit';
Expand All @@ -16,6 +15,7 @@ import { spawn } from 'child_process';
import customServer from './custom-server.impl';
import { createCliOptions } from '../../utils/create-cli-options';
import { createAsyncIterable } from '@nx/devkit/src/utils/async-iterable';
import { killTree } from '@nx/js/src/executors/node/lib/kill-tree';

export default async function* serveExecutor(
options: NextServeBuilderOptions,
Expand Down Expand Up @@ -86,27 +86,21 @@ export default async function* serveExecutor(
cwd: options.dev ? root : nextDir,
stdio: 'inherit',
shell: true,
windowsHide: true,
});

waitForServerReady();

server.once('exit', (code) => {
cleanupClient();
if (code === 0) {
done();
} else {
error(new Error(`Next.js app exited with code ${code}`));
}
});

process.on('exit', async (code) => {
if (code === 128 + 2) {
server.kill('SIGINT');
} else if (code === 128 + 1) {
server.kill('SIGHUP');
} else {
server.kill('SIGTERM');
}
process.on('exit', () => {
killTree(server.pid, 'SIGKILL');
});
}
);
Expand Down
17 changes: 5 additions & 12 deletions packages/node/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import path = require('path');
import json = require('./migrations.json');
import { MigrationsJsonEntry } from 'nx/src/config/misc-interfaces';

describe('Node migrations', () => {
it('should have valid paths', () => {
Object.values(json.generators).forEach((m: MigrationsJsonEntry) => {
expect(() =>
require.resolve(
path.join(__dirname, `${m.factory ?? m.implementation}.ts`)
)
).not.toThrow();
});
});
import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('node migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
33 changes: 33 additions & 0 deletions packages/nx/internal-testing-utils/assert-valid-migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
MigrationsJson,
MigrationsJsonEntry,
} from '../src/config/misc-interfaces';
import * as path from 'path';

export function assertValidMigrationPaths(json: MigrationsJson, root: string) {
Object.entries(json.generators).forEach(([generator, m]) => {
it(`should have valid path generator: ${generator}`, () => {
validateMigration(m, root);
});
});

Object.entries(json.schematics ?? {}).forEach(([schematic, m]) => {
it(`should have valid path schematic: ${schematic}`, () => {
validateMigration(m, root);
});
});
}

function validateMigration(m: MigrationsJsonEntry, root: string) {
const impl = m.factory ?? m.implementation;
const [implPath, implMember] = impl.includes('#')
? impl.split('#')
: [impl, null];
let implModule;
expect(() => {
implModule = require(path.join(root, `${implPath}.ts`));
}).not.toThrow();
if (implMember) {
expect(implModule).toHaveProperty(implMember);
}
}
Loading

0 comments on commit eb2feee

Please sign in to comment.