Skip to content

Commit

Permalink
chore: migrate to nx 16.10
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-stepanenko committed Oct 28, 2023
1 parent 58f5b47 commit 5befd20
Show file tree
Hide file tree
Showing 26 changed files with 527 additions and 315 deletions.
12 changes: 6 additions & 6 deletions e2e/qwik-nx-e2e/tests/__snapshots__/application.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ exports[`appGenerator e2e Basic behavior with app generator should run type chec
>  NX  Running type check for the \\"PROJECT_NAME\\"..
npx tsc --incremental --noEmit --pretty -p REPLACED_PATH/tsconfig.app.json
apps/PROJECT_NAME/src/routes/index.tsx:8:15 - error TS2322: Type 'string' is not assignable to type 'number'.
8 a = 'not-a-number';
   ~
libs/LIB_PROJECT_NAME/src/lib/LIB_PROJECT_NAME.tsx:7:22 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
LIB_PROJECT_NAME/src/lib/LIB_PROJECT_NAME.tsx:7:22 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
7 b.push(1);
   ~
PROJECT_NAME/src/routes/index.tsx:8:15 - error TS2322: Type 'string' is not assignable to type 'number'.
8 a = 'not-a-number';
   ~
Found 2 errors in 2 files.
Errors Files
1 apps/PROJECT_NAME/src/routes/index.tsx[90m:8[0m
1 libs/LIB_PROJECT_NAME/src/lib/LIB_PROJECT_NAME.tsx[90m:7[0m
1 LIB_PROJECT_NAME/src/lib/LIB_PROJECT_NAME.tsx[90m:7[0m
1 PROJECT_NAME/src/routes/index.tsx[90m:8[0m
Expand Down
18 changes: 12 additions & 6 deletions e2e/qwik-nx-e2e/tests/application-basic-behavior.suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
import { names } from '@nx/devkit';

export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
const isPreset = generator === 'preset';
const appPathPrefix = isPreset ? 'apps/' : '';
const libPathPrefix = isPreset ? 'libs/' : '';
const devServerPort = 4212;
const previewServerPort = 4232;
describe(`Basic behavior with ${generator} generator`, () => {
Expand All @@ -36,12 +39,11 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
beforeAll(async () => {
project = uniq('qwik-nx');
libProject = uniq('qwik-nx');
rootRoutePath = `apps/${project}/src/routes/index.tsx`;
libComponentPath = `libs/${libProject}/src/lib/${libProject}.tsx`;
rootRoutePath = `${appPathPrefix}${project}/src/routes/index.tsx`;
libComponentPath = `${libPathPrefix}${libProject}/src/lib/${libProject}.tsx`;
libComponentName = names(libProject).className;

const projectNameParam =
generator === 'preset' ? `--qwikAppName=${project}` : project;
const projectNameParam = isPreset ? `--qwikAppName=${project}` : project;

await runNxCommandAsync(
`generate qwik-nx:${generator} ${projectNameParam} --no-interactive`
Expand Down Expand Up @@ -91,10 +93,14 @@ export function testApplicationBasicBehavior(generator: 'app' | 'preset') {
`Successfully ran target build for project ${project}`
);
expect(() =>
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
checkFilesExist(
`dist/${appPathPrefix}${project}/client/q-manifest.json`
)
).not.toThrow();
expect(() =>
checkFilesExist(`dist/apps/${project}/server/entry.preview.mjs`)
checkFilesExist(
`dist/${appPathPrefix}${project}/server/entry.preview.mjs`
)
).not.toThrow();
},
DEFAULT_E2E_TIMEOUT
Expand Down
28 changes: 11 additions & 17 deletions e2e/qwik-nx-e2e/tests/micro-frontends.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,10 @@ describe('Micro-frontends e2e', () => {
it(
'should create host and remote applications',
async () => {
expect(() =>
checkFilesExist(`apps/${project}/vite.config.ts`)
).not.toThrow();
expect(() =>
checkFilesExist(`apps/${remote1}/vite.config.ts`)
).not.toThrow();
expect(() =>
checkFilesExist(`apps/${remote2}/vite.config.ts`)
).not.toThrow();
const configFilePath = `apps/${project}/src/config/remotes.json`;
expect(() => checkFilesExist(`${project}/vite.config.ts`)).not.toThrow();
expect(() => checkFilesExist(`${remote1}/vite.config.ts`)).not.toThrow();
expect(() => checkFilesExist(`${remote2}/vite.config.ts`)).not.toThrow();
const configFilePath = `${project}/src/config/remotes.json`;
expect(() => checkFilesExist(configFilePath)).not.toThrow();
const config = readJson(configFilePath);
expect(config[remote1]).toEqual('http://localhost:5174');
Expand All @@ -67,10 +61,10 @@ describe('Micro-frontends e2e', () => {
`Successfully ran target build for project ${name}`
);
expect(() =>
checkFilesExist(`dist/apps/${name}/client/q-manifest.json`)
checkFilesExist(`dist/${name}/client/q-manifest.json`)
).not.toThrow();
expect(() =>
checkFilesExist(`dist/apps/${name}/server/entry.preview.mjs`)
checkFilesExist(`dist/${name}/server/entry.preview.mjs`)
).not.toThrow();
};
await checkProject(project);
Expand Down Expand Up @@ -162,7 +156,7 @@ describe('Micro-frontends e2e', () => {
`Successfully ran target build for project ${remote3}`
);
expect(() =>
checkFilesExist(`dist/apps/${remote3}/server/entry.preview.mjs`)
checkFilesExist(`dist/${remote3}/server/entry.preview.mjs`)
).not.toThrow();

const runResult = await runHostAndRemotes(
Expand Down Expand Up @@ -281,7 +275,7 @@ async function previewHostAndRemotes(
const includesBuiltMessage = (remote: string) => {
// checking for the presence of ssr build output message to determine whether project has been built
return stripConsoleColors(output).includes(
`${remote.toUpperCase()} ../../dist/apps/${remote}/server/entry.preview.mjs`
`${remote.toUpperCase()} ../dist/${remote}/server/entry.preview.mjs`
);
};

Expand All @@ -300,7 +294,7 @@ async function previewHostAndRemotes(

// build output
builtHost ||= stripConsoleColors(output).includes(
`../../dist/apps/${hostName}/server/entry.preview.mjs`
`../dist/${hostName}/server/entry.preview.mjs`
);
builtRemote1 ||= includesBuiltMessage(remote1);
builtRemote2 ||= includesBuiltMessage(remote2);
Expand Down Expand Up @@ -339,8 +333,8 @@ async function previewHostAndRemotes(

const hasBuildOutputs = (projectName: string): boolean => {
try {
checkFilesExist(`dist/apps/${projectName}/client/q-manifest.json`);
checkFilesExist(`dist/apps/${projectName}/server/entry.preview.mjs`);
checkFilesExist(`dist/${projectName}/client/q-manifest.json`);
checkFilesExist(`dist/${projectName}/server/entry.preview.mjs`);
return true;
} catch {
return false;
Expand Down
6 changes: 2 additions & 4 deletions e2e/qwik-nx-e2e/tests/qwik-nx-cloudflare.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ describe('qwik nx cloudflare generator', () => {
`Successfully ran target build for project ${project}`
);
expect(() =>
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
checkFilesExist(`dist/${project}/client/q-manifest.json`)
).not.toThrow();
expect(() =>
checkFilesExist(
`dist/apps/${project}/server/entry.cloudflare-pages.js`
)
checkFilesExist(`dist/${project}/server/entry.cloudflare-pages.js`)
).not.toThrow();
},
DEFAULT_E2E_TIMEOUT
Expand Down
4 changes: 2 additions & 2 deletions e2e/qwik-nx-e2e/tests/qwik-nx-netlify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('qwik nx netlify generator', () => {
`Successfully ran target build for project ${project}`
);
expect(() =>
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
checkFilesExist(`dist/${project}/client/q-manifest.json`)
).not.toThrow();
expect(() =>
checkFilesExist(
`dist/apps/${project}/.netlify/edge-functions/entry.netlify-edge/entry.netlify-edge.js`
`dist/${project}/.netlify/edge-functions/entry.netlify-edge/entry.netlify-edge.js`
)
).not.toThrow();
},
Expand Down
21 changes: 9 additions & 12 deletions e2e/qwik-nx-e2e/tests/qwik-nx-vite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('qwikNxVite plugin e2e', () => {
// move header component into the library

// update import in layout.tsx
const layoutFilePath = `apps/${project}/src/routes/layout.tsx`;
const layoutFilePath = `${project}/src/routes/layout.tsx`;
let layoutFile = readFile(layoutFilePath);
layoutFile = layoutFile.replace(
`import Header from '../components/header/header';`,
Expand All @@ -65,8 +65,8 @@ describe('qwikNxVite plugin e2e', () => {
updateFile(layoutFilePath, layoutFile);

// move header component files
const headerFolderOldPath = `apps/${project}/src/components/header`;
const headerFolderNewPath = `libs/${headerLibName}/src/lib`;
const headerFolderOldPath = `${project}/src/components/header`;
const headerFolderNewPath = `${headerLibName}/src/lib`;
removeFile(`${headerFolderNewPath}/${headerLibName}.tsx`);
removeFile(`${headerFolderNewPath}/${headerLibName}.css`);
renameFile(
Expand All @@ -78,7 +78,7 @@ describe('qwikNxVite plugin e2e', () => {
`${headerFolderNewPath}/header.css`
);
updateFile(
`libs/${headerLibName}/src/index.ts`,
`${headerLibName}/src/index.ts`,
`export * from './lib/header';`
);

Expand All @@ -95,17 +95,14 @@ describe('qwikNxVite plugin e2e', () => {
updateFile(`${headerFolderNewPath}/header.tsx`, headerTsx);

// move icon component file
const qwikIconFolderNewPath = `libs/${iconLibName}/src/lib`;
const qwikIconFolderNewPath = `${iconLibName}/src/lib`;
removeFile(`${qwikIconFolderNewPath}/${iconLibName}.tsx`);
removeFile(`${qwikIconFolderNewPath}/${iconLibName}.css`);
renameFile(
`apps/${project}/src/components/icons/qwik.tsx`,
`${project}/src/components/icons/qwik.tsx`,
`${qwikIconFolderNewPath}/qwik.tsx`
);
updateFile(
`libs/${iconLibName}/src/index.ts`,
`export * from './lib/qwik';`
);
updateFile(`${iconLibName}/src/index.ts`, `export * from './lib/qwik';`);
}, DEFAULT_E2E_TIMEOUT);

it(
Expand All @@ -116,10 +113,10 @@ describe('qwikNxVite plugin e2e', () => {
`Successfully ran target build for project ${project}`
);
expect(() =>
checkFilesExist(`dist/apps/${project}/client/q-manifest.json`)
checkFilesExist(`dist/${project}/client/q-manifest.json`)
).not.toThrow();
expect(() =>
checkFilesExist(`dist/apps/${project}/server/entry.preview.mjs`)
checkFilesExist(`dist/${project}/server/entry.preview.mjs`)
).not.toThrow();
},
DEFAULT_E2E_TIMEOUT
Expand Down
13 changes: 5 additions & 8 deletions e2e/qwik-nx-e2e/tests/storybook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('qwikNxVite plugin e2e', () => {
);
await addAdditionalStories(appProject);
}, DEFAULT_E2E_TIMEOUT);
checkStorybookIsBuiltAndServed(appProject, 'apps');
checkStorybookIsBuiltAndServed(appProject);
});
describe('Applying storybook for existing library', () => {
beforeAll(async () => {
Expand All @@ -55,7 +55,7 @@ describe('qwikNxVite plugin e2e', () => {
);
await addAdditionalStories(libProject);
}, DEFAULT_E2E_TIMEOUT);
checkStorybookIsBuiltAndServed(libProject, 'libs');
checkStorybookIsBuiltAndServed(libProject);
});

describe('Generating a new library with storybook configuration', () => {
Expand All @@ -65,7 +65,7 @@ describe('qwikNxVite plugin e2e', () => {
);
await addAdditionalStories(secondLibProject);
}, DEFAULT_E2E_TIMEOUT);
checkStorybookIsBuiltAndServed(secondLibProject, 'libs');
checkStorybookIsBuiltAndServed(secondLibProject);
});
});
});
Expand All @@ -79,10 +79,7 @@ async function addAdditionalStories(projectName: string): Promise<void> {
);
}

function checkStorybookIsBuiltAndServed(
projectName: string,
type: 'apps' | 'libs'
) {
function checkStorybookIsBuiltAndServed(projectName: string) {
it(
`should be able to build storybook for the "${projectName}"`,
async () => {
Expand Down Expand Up @@ -115,7 +112,7 @@ function checkStorybookIsBuiltAndServed(
}
);

const mdxPattern = normalize(`${type}/${projectName}/**/*.stories.mdx`);
const mdxPattern = normalize(`${projectName}/**/*.stories.mdx`);

// it is expected that projects won't have stories by default and storybook should recognize it.
expect(resultOutput).toContain(
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"@commitlint/config-angular": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@jscutlery/semver": "^3.1.0",
"@nx/cypress": "16.7.0",
"@nx/devkit": "16.7.0",
"@nx/eslint-plugin": "16.7.0",
"@nx/jest": "16.7.0",
"@nx/js": "16.7.0",
"@nx/linter": "16.7.0",
"@nx/plugin": "16.7.0",
"@nx/storybook": "16.7.0",
"@nx/vite": "16.7.0",
"@nx/workspace": "16.7.0",
"@nx/cypress": "16.10.0",
"@nx/devkit": "16.10.0",
"@nx/eslint-plugin": "16.10.0",
"@nx/jest": "16.10.0",
"@nx/js": "16.10.0",
"@nx/linter": "16.10.0",
"@nx/plugin": "16.10.0",
"@nx/storybook": "16.10.0",
"@nx/vite": "16.10.0",
"@nx/workspace": "16.10.0",
"@nxkit/playwright": "^3.0.2",
"@swc-node/register": "^1.4.2",
"@swc-node/register": "1.6.8",
"@swc/cli": "0.1.62",
"@swc/core": "^1.2.173",
"@types/fs-extra": "11.0.1",
Expand Down Expand Up @@ -63,8 +63,8 @@
"jsonc-eslint-parser": "^2.1.0",
"kill-port": "2.0.1",
"ngx-deploy-npm": "^6.0.0",
"nx": "16.7.0",
"nx-cloud": "16.3.0",
"nx": "16.10.0",
"nx-cloud": "16.5.2",
"prettier": "^2.8.0",
"pretty-quick": "^3.1.3",
"tcp-port-used": "1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik-nx/src/generators/application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function appGenerator(
tree: Tree,
options: QwikAppGeneratorSchema
) {
const normalizedOptions = normalizeOptions(tree, options);
const normalizedOptions = await normalizeOptions(tree, options);
const tasks: GeneratorCallback[] = [];

const targets: Record<string, TargetConfiguration> =
Expand Down
4 changes: 3 additions & 1 deletion packages/qwik-nx/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Linter } from '@nx/linter';
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';

export interface QwikAppGeneratorSchema {
name: string;
Expand All @@ -13,7 +14,7 @@ export interface QwikAppGeneratorSchema {
e2eTestRunner?: 'playwright' | 'cypress' | 'none';
devServerPort?: number;
previewServerPort?: number;
// router: 'qwik-city' | 'none'; // TODO: add setup w/o qwik-city
projectNameAndRootFormat?: ProjectNameAndRootFormat;
}

export interface NormalizedSchema extends QwikAppGeneratorSchema {
Expand All @@ -26,4 +27,5 @@ export interface NormalizedSchema extends QwikAppGeneratorSchema {
setupVitest: boolean;
parsedTags: string[];
styleExtension: Exclude<QwikAppGeneratorSchema['style'], 'none'> | null;
projectNameAndRootFormat: ProjectNameAndRootFormat;
}
5 changes: 5 additions & 0 deletions packages/qwik-nx/src/generators/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"default": "css"
}
},
"projectNameAndRootFormat": {
"description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
"type": "string",
"enum": ["as-provided", "derived"]
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
Expand Down
Loading

0 comments on commit 5befd20

Please sign in to comment.