Skip to content

Commit f0e4d5d

Browse files
feat: make the repo stricter (#83)
1 parent fcab2f9 commit f0e4d5d

28 files changed

+201
-88
lines changed

.eslintrc.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"root": true,
33
"ignorePatterns": ["**/*"],
4-
"plugins": ["@nrwl/nx"],
4+
"plugins": ["@nrwl/nx", "eslint-plugin-unused-imports"],
55
"overrides": [
66
{
77
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
@@ -24,7 +24,24 @@
2424
{
2525
"files": ["*.ts", "*.tsx"],
2626
"extends": ["plugin:@nrwl/nx/typescript"],
27-
"rules": {}
27+
"rules": {
28+
"@typescript-eslint/no-var-requires": "off",
29+
"@typescript-eslint/no-non-null-assertion": "off",
30+
"unused-imports/no-unused-imports": "error",
31+
"no-duplicate-imports": "error",
32+
"unused-imports/no-unused-vars": "error",
33+
"@typescript-eslint/naming-convention": [
34+
"error",
35+
{
36+
"selector": "enum",
37+
"format": ["PascalCase"]
38+
},
39+
{
40+
"selector": "enumMember",
41+
"format": ["PascalCase"]
42+
}
43+
]
44+
}
2845
},
2946
{
3047
"files": ["*.js", "*.jsx"],
@@ -36,7 +53,9 @@
3653
"env": {
3754
"jest": true
3855
},
39-
"rules": {}
56+
"rules": {
57+
"no-restricted-globals": ["error", "fdescribe", "fit"]
58+
}
4059
},
4160
{
4261
"files": "*.json",

e2e/qwik-nx-e2e/tests/application.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('appGenerator e2e', () => {
5959
}
6060
);
6161
try {
62-
await promisifiedTreeKill(p.pid, 'SIGKILL');
62+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
6363
await killPort(port);
6464
} catch {
6565
// ignore
@@ -75,7 +75,7 @@ describe('appGenerator e2e', () => {
7575
}
7676
);
7777
try {
78-
await promisifiedTreeKill(p.pid, 'SIGKILL');
78+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
7979
await killPort(port);
8080
} catch {
8181
// ignore

e2e/qwik-nx-e2e/tests/qwik-nx-vite.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('qwikNxVite plugin e2e', () => {
127127
}
128128
);
129129
try {
130-
await promisifiedTreeKill(p.pid, 'SIGKILL');
130+
await promisifiedTreeKill(p.pid!, 'SIGKILL');
131131
await killPort(port);
132132
} catch {
133133
// ignore

e2e/utils/index.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,31 @@ export const promisifiedTreeKill: (
2020
signal: string
2121
) => Promise<void> = promisify(treeKill);
2222

23-
function getAdditionalPackageManagerCommands() {
23+
function getAdditionalPackageManagerCommands(): {
24+
createWorkspace: string;
25+
runNx: string;
26+
} {
2427
const pm = detectPackageManager();
2528
const [npmMajorVersion] = execSync(`npm -v`).toString().split('.');
2629
const publishedVersion = execSync('npm view nx version');
27-
if (pm === 'npm') {
28-
return {
29-
createWorkspace: `npx ${
30-
+npmMajorVersion >= 7 ? '--yes' : ''
31-
} create-nx-workspace@${publishedVersion}`,
32-
runNx: `npx nx`,
33-
};
34-
} else if (pm === 'yarn') {
35-
return {
36-
createWorkspace: `yarn global add create-nx-workspace@${publishedVersion} && create-nx-workspace`,
37-
runNx: `yarn nx`,
38-
};
39-
} else if (pm === 'pnpm') {
40-
return {
41-
createWorkspace: `pnpm dlx create-nx-workspace@${publishedVersion}`,
42-
runNx: `pnpm exec nx`,
43-
};
30+
switch (pm) {
31+
case 'npm':
32+
return {
33+
createWorkspace: `npx ${
34+
+npmMajorVersion >= 7 ? '--yes' : ''
35+
} create-nx-workspace@${publishedVersion}`,
36+
runNx: `npx nx`,
37+
};
38+
case 'yarn':
39+
return {
40+
createWorkspace: `yarn global add create-nx-workspace@${publishedVersion} && create-nx-workspace`,
41+
runNx: `yarn nx`,
42+
};
43+
case 'pnpm':
44+
return {
45+
createWorkspace: `pnpm dlx create-nx-workspace@${publishedVersion}`,
46+
runNx: `pnpm exec nx`,
47+
};
4448
}
4549
}
4650

@@ -149,7 +153,7 @@ export function runCommandUntil(
149153
let output = '';
150154
let complete = false;
151155

152-
function checkCriteria(c) {
156+
function checkCriteria(c: any) {
153157
output += c.toString();
154158
if (criteria(stripConsoleColors(output)) && !complete) {
155159
complete = true;

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
"@swc-node/register": "^1.4.2",
3232
"@swc/cli": "~0.1.55",
3333
"@swc/core": "^1.2.173",
34+
"@types/fs-extra": "11.0.1",
3435
"@types/jest": "28.1.1",
3536
"@types/node": "16.11.7",
37+
"@types/tcp-port-used": "1.0.1",
3638
"@typescript-eslint/eslint-plugin": "^5.36.1",
3739
"@typescript-eslint/parser": "^5.36.1",
3840
"all-contributors-cli": "^6.24.0",
@@ -42,8 +44,10 @@
4244
"cz-conventional-changelog": "^3.3.0",
4345
"eslint": "~8.15.0",
4446
"eslint-config-prettier": "8.1.0",
47+
"eslint-plugin-unused-imports": "2.0.0",
4548
"fs-extra": "11.1.0",
4649
"husky": "^8.0.1",
50+
"is-windows": "1.0.2",
4751
"jest": "28.1.1",
4852
"jest-environment-jsdom": "28.1.1",
4953
"jsonc-eslint-parser": "^2.1.0",

packages/add-nx-to-qwik/src/add-nx-to-qwik.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function addNxToMonorepo() {
4444

4545
let targetDefaults: string[];
4646
let cacheableOperations: string[];
47-
let scriptOutputs = {};
47+
const scriptOutputs = {};
4848
let useCloud: boolean;
4949

5050
if (parsedArgs.yes !== true) {

packages/qwik-nx/src/generators/application/generator.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Linter } from '@nrwl/linter';
77

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

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

2324
jest.spyOn(devkit, 'ensurePackage').mockReturnValue(Promise.resolve());
25+
jest
26+
.spyOn(getInstalledNxVersionModule, 'getInstalledNxVersion')
27+
.mockReturnValue('15.6.0');
2428

2529
beforeEach(() => {
2630
appTree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
@@ -50,7 +54,7 @@ describe('qwik-nx generator', () => {
5054
});
5155
const config = readProjectConfiguration(appTree, 'myapp-e2e');
5256
expect(config).toBeDefined();
53-
expect(config.targets.e2e.executor).toEqual('@nxkit/playwright:test');
57+
expect(config.targets?.e2e.executor).toEqual('@nxkit/playwright:test');
5458
expect(
5559
appTree.exists('apps/myapp-e2e/playwright.config.ts')
5660
).toBeTruthy();
@@ -63,7 +67,7 @@ describe('qwik-nx generator', () => {
6367
});
6468
const config = readProjectConfiguration(appTree, 'myapp-e2e');
6569
expect(config).toBeDefined();
66-
expect(config.targets.e2e.executor).toEqual('@nrwl/cypress:cypress');
70+
expect(config.targets?.e2e.executor).toEqual('@nrwl/cypress:cypress');
6771
expect(appTree.exists('apps/myapp-e2e/cypress.config.ts')).toBeTruthy();
6872
});
6973
});

packages/qwik-nx/src/generators/application/generator.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
GeneratorCallback,
66
joinPathFragments,
77
names,
8+
TargetConfiguration,
89
Tree,
910
} from '@nrwl/devkit';
1011
import { Linter } from '@nrwl/linter';
@@ -41,7 +42,8 @@ export async function appGenerator(
4142
const normalizedOptions = normalizeOptions(tree, options);
4243
const tasks: GeneratorCallback[] = [];
4344

44-
const targets = getQwikApplicationProjectTargets(normalizedOptions);
45+
const targets: Record<string, TargetConfiguration> =
46+
getQwikApplicationProjectTargets(normalizedOptions);
4547

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

72-
if (normalizedOptions.style !== 'none') {
74+
if (normalizedOptions.styleExtension) {
7375
tasks.push(
7476
addStyledModuleDependencies(tree, normalizedOptions.styleExtension)
7577
);
7678
}
7779

7880
tasks.push(addCommonQwikDependencies(tree));
7981

80-
if (normalizedOptions.e2eTestRunner !== 'none') {
82+
if (
83+
normalizedOptions.e2eTestRunner &&
84+
normalizedOptions.e2eTestRunner !== 'none'
85+
) {
8186
const e2eProjectTask = await addE2eProject(tree, {
8287
project: normalizedOptions.projectName,
8388
directory: normalizedOptions.directory,

packages/qwik-nx/src/generators/application/utils/get-qwik-application-project-params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface UpdateQwikAppConfigurationParams {
88

99
export function getQwikApplicationProjectTargets(
1010
params: UpdateQwikAppConfigurationParams
11-
) {
11+
): Record<string, TargetConfiguration> {
1212
return {
1313
build: getBuildTarget(params),
1414
'build-ssr': getBuildSsrTarget(params),

packages/qwik-nx/src/generators/component/generator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
formatFiles,
33
generateFiles,
4+
GeneratorCallback,
45
getProjects,
56
joinPathFragments,
67
logger,
@@ -23,7 +24,7 @@ function getDirectory(host: Tree, options: ComponentGeneratorSchema) {
2324
baseDir = options.directory;
2425
} else {
2526
baseDir =
26-
workspace.get(options.project).projectType === 'application'
27+
workspace.get(options.project)!.projectType === 'application'
2728
? 'components'
2829
: 'lib';
2930
}
@@ -45,7 +46,8 @@ function normalizeOptions(
4546
throw new Error();
4647
}
4748

48-
const { sourceRoot: projectRoot } = project;
49+
const projectRoot =
50+
project.sourceRoot ?? joinPathFragments(project.root, 'src');
4951

5052
const directory = getDirectory(host, options);
5153

@@ -98,7 +100,7 @@ function createComponentFiles(tree: Tree, options: NormalizedSchema) {
98100
export async function componentGenerator(
99101
tree: Tree,
100102
options: ComponentGeneratorSchema
101-
) {
103+
): Promise<GeneratorCallback> {
102104
const normalizedOptions = normalizeOptions(tree, options);
103105
createComponentFiles(tree, normalizedOptions);
104106
await formatFiles(tree);

0 commit comments

Comments
 (0)