Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"plugins": ["@nrwl/nx", "eslint-plugin-unused-imports"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
Expand All @@ -24,7 +24,24 @@
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"unused-imports/no-unused-imports": "error",
"no-duplicate-imports": "error",
"unused-imports/no-unused-vars": "error",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "enum",
"format": ["PascalCase"]
},
{
"selector": "enumMember",
"format": ["PascalCase"]
}
]
}
},
{
"files": ["*.js", "*.jsx"],
Expand All @@ -36,7 +53,9 @@
"env": {
"jest": true
},
"rules": {}
"rules": {
"no-restricted-globals": ["error", "fdescribe", "fit"]
}
},
{
"files": "*.json",
Expand Down
4 changes: 2 additions & 2 deletions e2e/qwik-nx-e2e/tests/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('appGenerator e2e', () => {
}
);
try {
await promisifiedTreeKill(p.pid, 'SIGKILL');
await promisifiedTreeKill(p.pid!, 'SIGKILL');
await killPort(port);
} catch {
// ignore
Expand All @@ -75,7 +75,7 @@ describe('appGenerator e2e', () => {
}
);
try {
await promisifiedTreeKill(p.pid, 'SIGKILL');
await promisifiedTreeKill(p.pid!, 'SIGKILL');
await killPort(port);
} catch {
// ignore
Expand Down
2 changes: 1 addition & 1 deletion e2e/qwik-nx-e2e/tests/qwik-nx-vite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('qwikNxVite plugin e2e', () => {
}
);
try {
await promisifiedTreeKill(p.pid, 'SIGKILL');
await promisifiedTreeKill(p.pid!, 'SIGKILL');
await killPort(port);
} catch {
// ignore
Expand Down
42 changes: 23 additions & 19 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,31 @@ export const promisifiedTreeKill: (
signal: string
) => Promise<void> = promisify(treeKill);

function getAdditionalPackageManagerCommands() {
function getAdditionalPackageManagerCommands(): {
createWorkspace: string;
runNx: string;
} {
const pm = detectPackageManager();
const [npmMajorVersion] = execSync(`npm -v`).toString().split('.');
const publishedVersion = execSync('npm view nx version');
if (pm === 'npm') {
return {
createWorkspace: `npx ${
+npmMajorVersion >= 7 ? '--yes' : ''
} create-nx-workspace@${publishedVersion}`,
runNx: `npx nx`,
};
} else if (pm === 'yarn') {
return {
createWorkspace: `yarn global add create-nx-workspace@${publishedVersion} && create-nx-workspace`,
runNx: `yarn nx`,
};
} else if (pm === 'pnpm') {
return {
createWorkspace: `pnpm dlx create-nx-workspace@${publishedVersion}`,
runNx: `pnpm exec nx`,
};
switch (pm) {
case 'npm':
return {
createWorkspace: `npx ${
+npmMajorVersion >= 7 ? '--yes' : ''
} create-nx-workspace@${publishedVersion}`,
runNx: `npx nx`,
};
case 'yarn':
return {
createWorkspace: `yarn global add create-nx-workspace@${publishedVersion} && create-nx-workspace`,
runNx: `yarn nx`,
};
case 'pnpm':
return {
createWorkspace: `pnpm dlx create-nx-workspace@${publishedVersion}`,
runNx: `pnpm exec nx`,
};
}
}

Expand Down Expand Up @@ -149,7 +153,7 @@ export function runCommandUntil(
let output = '';
let complete = false;

function checkCriteria(c) {
function checkCriteria(c: any) {
output += c.toString();
if (criteria(stripConsoleColors(output)) && !complete) {
complete = true;
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
"@swc-node/register": "^1.4.2",
"@swc/cli": "~0.1.55",
"@swc/core": "^1.2.173",
"@types/fs-extra": "11.0.1",
"@types/jest": "28.1.1",
"@types/node": "16.11.7",
"@types/tcp-port-used": "1.0.1",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"all-contributors-cli": "^6.24.0",
Expand All @@ -42,8 +44,10 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "~8.15.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-unused-imports": "2.0.0",
"fs-extra": "11.1.0",
"husky": "^8.0.1",
"is-windows": "1.0.2",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"jsonc-eslint-parser": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/add-nx-to-qwik/src/add-nx-to-qwik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function addNxToMonorepo() {

let targetDefaults: string[];
let cacheableOperations: string[];
let scriptOutputs = {};
const scriptOutputs = {};
let useCloud: boolean;

if (parsedArgs.yes !== true) {
Expand Down
8 changes: 6 additions & 2 deletions packages/qwik-nx/src/generators/application/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Linter } from '@nrwl/linter';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const devkit = require('@nrwl/devkit');
const getInstalledNxVersionModule = require('../../utils/get-installed-nx-version');

describe('qwik-nx generator', () => {
let appTree: Tree;
Expand All @@ -21,6 +22,9 @@ describe('qwik-nx generator', () => {
};

jest.spyOn(devkit, 'ensurePackage').mockReturnValue(Promise.resolve());
jest
.spyOn(getInstalledNxVersionModule, 'getInstalledNxVersion')
.mockReturnValue('15.6.0');

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
Expand Down Expand Up @@ -50,7 +54,7 @@ describe('qwik-nx generator', () => {
});
const config = readProjectConfiguration(appTree, 'myapp-e2e');
expect(config).toBeDefined();
expect(config.targets.e2e.executor).toEqual('@nxkit/playwright:test');
expect(config.targets?.e2e.executor).toEqual('@nxkit/playwright:test');
expect(
appTree.exists('apps/myapp-e2e/playwright.config.ts')
).toBeTruthy();
Expand All @@ -63,7 +67,7 @@ describe('qwik-nx generator', () => {
});
const config = readProjectConfiguration(appTree, 'myapp-e2e');
expect(config).toBeDefined();
expect(config.targets.e2e.executor).toEqual('@nrwl/cypress:cypress');
expect(config.targets?.e2e.executor).toEqual('@nrwl/cypress:cypress');
expect(appTree.exists('apps/myapp-e2e/cypress.config.ts')).toBeTruthy();
});
});
Expand Down
11 changes: 8 additions & 3 deletions packages/qwik-nx/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GeneratorCallback,
joinPathFragments,
names,
TargetConfiguration,
Tree,
} from '@nrwl/devkit';
import { Linter } from '@nrwl/linter';
Expand Down Expand Up @@ -41,7 +42,8 @@ export async function appGenerator(
const normalizedOptions = normalizeOptions(tree, options);
const tasks: GeneratorCallback[] = [];

const targets = getQwikApplicationProjectTargets(normalizedOptions);
const targets: Record<string, TargetConfiguration> =
getQwikApplicationProjectTargets(normalizedOptions);

if (!normalizedOptions.setupVitest) {
delete targets['test'];
Expand Down Expand Up @@ -69,15 +71,18 @@ export async function appGenerator(
tasks.push(configureEslint(tree, normalizedOptions.projectName, true));
}

if (normalizedOptions.style !== 'none') {
if (normalizedOptions.styleExtension) {
tasks.push(
addStyledModuleDependencies(tree, normalizedOptions.styleExtension)
);
}

tasks.push(addCommonQwikDependencies(tree));

if (normalizedOptions.e2eTestRunner !== 'none') {
if (
normalizedOptions.e2eTestRunner &&
normalizedOptions.e2eTestRunner !== 'none'
) {
const e2eProjectTask = await addE2eProject(tree, {
project: normalizedOptions.projectName,
directory: normalizedOptions.directory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface UpdateQwikAppConfigurationParams {

export function getQwikApplicationProjectTargets(
params: UpdateQwikAppConfigurationParams
) {
): Record<string, TargetConfiguration> {
return {
build: getBuildTarget(params),
'build-ssr': getBuildSsrTarget(params),
Expand Down
8 changes: 5 additions & 3 deletions packages/qwik-nx/src/generators/component/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
formatFiles,
generateFiles,
GeneratorCallback,
getProjects,
joinPathFragments,
logger,
Expand All @@ -23,7 +24,7 @@ function getDirectory(host: Tree, options: ComponentGeneratorSchema) {
baseDir = options.directory;
} else {
baseDir =
workspace.get(options.project).projectType === 'application'
workspace.get(options.project)!.projectType === 'application'
? 'components'
: 'lib';
}
Expand All @@ -45,7 +46,8 @@ function normalizeOptions(
throw new Error();
}

const { sourceRoot: projectRoot } = project;
const projectRoot =
project.sourceRoot ?? joinPathFragments(project.root, 'src');

const directory = getDirectory(host, options);

Expand Down Expand Up @@ -98,7 +100,7 @@ function createComponentFiles(tree: Tree, options: NormalizedSchema) {
export async function componentGenerator(
tree: Tree,
options: ComponentGeneratorSchema
) {
): Promise<GeneratorCallback> {
const normalizedOptions = normalizeOptions(tree, options);
createComponentFiles(tree, normalizedOptions);
await formatFiles(tree);
Expand Down
8 changes: 6 additions & 2 deletions packages/qwik-nx/src/generators/e2e-project/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { E2eProjectGeneratorSchema } from './schema';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const devkit = require('@nrwl/devkit');
const getInstalledNxVersionModule = require('../../utils/get-installed-nx-version');

describe('e2e project', () => {
let appTree: Tree;
Expand All @@ -15,6 +16,9 @@ describe('e2e project', () => {
};

jest.spyOn(devkit, 'ensurePackage').mockReturnValue(Promise.resolve());
jest
.spyOn(getInstalledNxVersionModule, 'getInstalledNxVersion')
.mockReturnValue('15.6.0');

beforeEach(() => {
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
Expand All @@ -31,7 +35,7 @@ describe('e2e project', () => {
});
const config = readProjectConfiguration(appTree, 'myapp-e2e');
expect(config).toBeDefined();
expect(config.targets.e2e.executor).toEqual('@nxkit/playwright:test');
expect(config.targets?.e2e.executor).toEqual('@nxkit/playwright:test');
expect(appTree.exists('apps/myapp-e2e/playwright.config.ts')).toBeTruthy();
});

Expand All @@ -42,7 +46,7 @@ describe('e2e project', () => {
});
const config = readProjectConfiguration(appTree, 'myapp-e2e');
expect(config).toBeDefined();
expect(config.targets.e2e.executor).toEqual('@nrwl/cypress:cypress');
expect(config.targets?.e2e.executor).toEqual('@nrwl/cypress:cypress');
expect(appTree.exists('apps/myapp-e2e/cypress.config.ts')).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions packages/qwik-nx/src/generators/e2e-project/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export async function addE2eProject(
if (options.e2eTestRunner === 'playwright') {
return addPlaywright(tree, normalizedOptions);
}

return () => void 0;
}

async function addCypress(tree: Tree, options: NormalizedSchema) {
Expand Down
16 changes: 8 additions & 8 deletions packages/qwik-nx/src/generators/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export { appGenerator } from './application/generator';
export { QwikAppGeneratorSchema } from './application/schema';
export type { QwikAppGeneratorSchema } from './application/schema';
export { componentGenerator } from './component/generator';
export { ComponentGeneratorSchema } from './component/schema';
export type { ComponentGeneratorSchema } from './component/schema';
export { addE2eProject } from './e2e-project/generator';
export { E2eProjectGeneratorSchema } from './e2e-project/schema';
export type { E2eProjectGeneratorSchema } from './e2e-project/schema';
export { qwikInitGenerator } from './init/init';
export { InitGeneratorSchema } from './init/schema';
export type { InitGeneratorSchema } from './init/schema';
export { cloudflarePagesIntegrationGenerator } from './integrations/cloudflare-pages-integration/generator';
export { CloudflarePagesIntegrationGeneratorSchema } from './integrations/cloudflare-pages-integration/schema';
export type { CloudflarePagesIntegrationGeneratorSchema } from './integrations/cloudflare-pages-integration/schema';
export { libraryGenerator } from './library/generator';
export { LibraryGeneratorSchema } from './library/schema';
export type { LibraryGeneratorSchema } from './library/schema';
export { routeGenerator } from './route/generator';
export { RouteGeneratorSchema } from './route/schema';
export type { RouteGeneratorSchema } from './route/schema';
export { setupTailwindGenerator } from './setup-tailwind/setup-tailwind';
export { SetupTailwindOptions } from './setup-tailwind/schema';
export type { SetupTailwindOptions } from './setup-tailwind/schema';
Loading