Skip to content

Commit 8de47ab

Browse files
feat(qwik-nx): update target & configuration names
1 parent d632c7c commit 8de47ab

File tree

11 files changed

+139
-98
lines changed

11 files changed

+139
-98
lines changed

e2e/qwik-nx-e2e/tests/application-basic-behavior.suite.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
runCommandUntil,
1010
promisifiedTreeKill,
1111
killPort,
12+
stripConsoleColors,
1213
} from '@qwikifiers/e2e/utils';
1314

1415
export function testApplicationBasicBehavior(generator: 'app' | 'preset') {

packages/qwik-nx/src/executors/build/executor.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Build Executor', () => {
3030
} as ExecutorContext;
3131

3232
const options: BuildExecutorSchema = {
33-
sequence: ['my-app:target1:development', 'my-app:target2'],
33+
runSequence: ['my-app:target1:development', 'my-app:target2'],
3434
};
3535
const iterable = executor(options, context);
3636
await iterable.next();

packages/qwik-nx/src/executors/build/executor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export default async function* runBuildExecutor(
1212
options: BuildExecutorSchema,
1313
context: ExecutorContext
1414
) {
15-
const configs = options.sequence.map((target) => {
16-
const cfg = parseTargetString(target, context.projectGraph);
15+
const configs = options.runSequence.map((target) => {
16+
const cfg = parseTargetString(target, context.projectGraph!);
1717
cfg.configuration ??= context.configurationName;
1818
return cfg;
1919
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export interface BuildExecutorSchema {
2-
sequence: string[];
2+
runSequence: string[];
33
}

packages/qwik-nx/src/executors/build/schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"description": "",
77
"type": "object",
88
"properties": {
9-
"sequence": {
9+
"runSequence": {
1010
"description": "An array of targets to be executed in a sequence",
1111
"type": "array",
1212
"items": {
@@ -15,5 +15,5 @@
1515
}
1616
}
1717
},
18-
"required": ["sequence"]
18+
"required": ["runSequence"]
1919
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getBuildTarget(
2626
return {
2727
executor: 'qwik-nx:build',
2828
options: {
29-
sequence: [
29+
runSequence: [
3030
`${params.projectName}:build.client`,
3131
`${params.projectName}:build.ssr`,
3232
],
@@ -98,21 +98,10 @@ function getServeTarget(
9898
): TargetConfiguration {
9999
return {
100100
executor: '@nrwl/vite:dev-server',
101-
defaultConfiguration: 'development',
102101
options: {
103-
buildTarget: `${params.projectName}:build.client`, // TODO?
102+
buildTarget: `${params.projectName}:build.client`,
104103
mode: 'ssr',
105104
},
106-
configurations: {
107-
development: {
108-
buildTarget: `${params.projectName}:build.client:development`,
109-
hmr: true,
110-
},
111-
production: {
112-
buildTarget: `${params.projectName}:build.client:production`,
113-
hmr: false,
114-
},
115-
},
116105
};
117106
}
118107

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/generator.spec.ts

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,72 @@ describe('cloudflare-pages-integration generator', () => {
3535
it('should add required targets', async () => {
3636
await cloudflarePagesIntegrationGenerator(appTree, options);
3737
const config = readProjectConfiguration(appTree, projectName);
38-
expect(
39-
config.targets!['build.ssr'].configurations!['cloudflare-pages']
40-
).toEqual({
38+
expect(config.targets!['build.ssr'].configurations!['production']).toEqual({
4139
configFile: `apps/${projectName}/adaptors/cloudflare-pages/vite.config.ts`,
4240
});
4341
expect(config.targets!['deploy']).toEqual({
4442
executor: '@k11r/nx-cloudflare-wrangler:deploy-page',
4543
options: {
4644
dist: `dist/apps/${projectName}/client`,
4745
},
48-
dependsOn: ['build-cloudflare-pages'],
46+
dependsOn: ['build-cloudflare'],
4947
});
50-
expect(config.targets!['preview-cloudflare-pages']).toEqual({
48+
expect(config.targets!['preview-cloudflare']).toEqual({
5149
executor: '@k11r/nx-cloudflare-wrangler:serve-page',
5250
options: {
5351
dist: `dist/apps/${projectName}/client`,
5452
},
55-
dependsOn: ['build-cloudflare-pages'],
53+
dependsOn: ['build-cloudflare'],
5654
});
57-
expect(config.targets!['build-cloudflare-pages']).toEqual({
55+
expect(config.targets!['build-cloudflare']).toEqual({
5856
executor: 'nx:run-commands',
5957
options: {
60-
command: `npx nx run ${projectName}:build:cloudflare-pages`,
58+
command: `npx nx run ${projectName}:build:production`,
59+
},
60+
});
61+
});
62+
63+
it('should use other target name if deploy target is already defined', async () => {
64+
const configBefore = readProjectConfiguration(appTree, projectName);
65+
configBefore.targets!['deploy'] = { executor: 'nx:noop' };
66+
updateProjectConfiguration(appTree, projectName, configBefore);
67+
68+
await cloudflarePagesIntegrationGenerator(appTree, options);
69+
70+
const config = readProjectConfiguration(appTree, projectName);
71+
expect(config.targets!['build.ssr'].configurations!['production']).toEqual({
72+
configFile: `apps/${projectName}/adaptors/cloudflare-pages/vite.config.ts`,
73+
});
74+
expect(config.targets!['deploy']).toEqual({ executor: 'nx:noop' });
75+
expect(config.targets!['deploy.cloudflare'].executor).toEqual(
76+
'@k11r/nx-cloudflare-wrangler:deploy-page'
77+
);
78+
});
79+
80+
it('should use the name of the integration if configuration name "production" is already defined', async () => {
81+
const configBefore = readProjectConfiguration(appTree, projectName);
82+
configBefore.targets!['build.ssr'].configurations!['production'] = {};
83+
updateProjectConfiguration(appTree, projectName, configBefore);
84+
85+
await cloudflarePagesIntegrationGenerator(appTree, options);
86+
87+
const config = readProjectConfiguration(appTree, projectName);
88+
expect(
89+
config.targets!['build'].configurations!['production']
90+
).toBeUndefined();
91+
expect(config.targets!['build.ssr'].configurations!['production']).toEqual(
92+
{}
93+
);
94+
expect(config.targets!['build.ssr'].configurations!['cloudflare']).toEqual({
95+
configFile: `apps/${projectName}/adaptors/cloudflare-pages/vite.config.ts`,
96+
});
97+
expect(config.targets!['deploy'].executor).toEqual(
98+
'@k11r/nx-cloudflare-wrangler:deploy-page'
99+
);
100+
expect(config.targets!['build-cloudflare']).toEqual({
101+
executor: 'nx:run-commands',
102+
options: {
103+
command: `npx nx run ${projectName}:build:cloudflare`,
61104
},
62105
});
63106
});
@@ -70,17 +113,6 @@ describe('cloudflare-pages-integration generator', () => {
70113
});
71114

72115
describe('should throw if project configuration does not meet the expectations', () => {
73-
it('deploy target is already defined', async () => {
74-
const config = readProjectConfiguration(appTree, projectName);
75-
config.targets!['deploy'] = { executor: 'nx:noop' };
76-
updateProjectConfiguration(appTree, projectName, config);
77-
78-
expect(
79-
cloudflarePagesIntegrationGenerator(appTree, options)
80-
).rejects.toThrow(
81-
`"deploy" target has already been configured for ${options.project}`
82-
);
83-
});
84116
it('project is not an application', async () => {
85117
const config = readProjectConfiguration(appTree, projectName);
86118
config.projectType = 'library';
@@ -95,14 +127,12 @@ describe('cloudflare-pages-integration generator', () => {
95127

96128
it('project does not have Qwik\'s "build-ssr" target', async () => {
97129
const config = readProjectConfiguration(appTree, projectName);
98-
config.targets!.build.executor = 'changed';
130+
config.targets!.build.executor = 'nx:run-commands';
99131
updateProjectConfiguration(appTree, projectName, config);
100132

101133
await expect(
102134
cloudflarePagesIntegrationGenerator(appTree, options)
103-
).rejects.toThrow(
104-
'Cannot setup cloudflare integration for the given project.'
105-
);
135+
).rejects.toThrow('Project contains invalid configuration.');
106136
});
107137
});
108138
});

packages/qwik-nx/src/generators/integrations/cloudflare-pages-integration/generator.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import {
66
joinPathFragments,
77
names,
88
offsetFromRoot,
9-
output,
109
ProjectConfiguration,
1110
readProjectConfiguration,
1211
TargetConfiguration,
1312
Tree,
1413
updateProjectConfiguration,
1514
} from '@nrwl/devkit';
15+
import {
16+
getIntegrationConfigurationName,
17+
IntegrationName,
18+
} from '../../../utils/integration-configuration-name';
1619
import { nxCloudflareWrangler, wranglerVersion } from '../../../utils/versions';
1720
import { CloudflarePagesIntegrationGeneratorSchema } from './schema';
1821

@@ -26,33 +29,37 @@ export async function cloudflarePagesIntegrationGenerator(
2629
options: CloudflarePagesIntegrationGeneratorSchema
2730
) {
2831
const config = readProjectConfiguration(tree, options.project);
29-
if (
30-
config.projectType !== 'application' ||
31-
config.targets?.['build']?.executor !== 'qwik-nx:build'
32-
) {
33-
console.error(
34-
'Project contains invalid configuration. ' +
35-
'If you encounter this error within a Qwik project, make sure you have run necessary Nx migrations for qwik-nx plugin.'
36-
);
32+
if (config.projectType !== 'application') {
3733
throw new Error(
3834
'Cannot setup cloudflare integration for the given project.'
3935
);
4036
}
41-
if (config.targets['deploy']) {
37+
if (config.targets?.['build']?.executor !== 'qwik-nx:build') {
4238
throw new Error(
43-
`"deploy" target has already been configured for ${options.project}`
39+
'Project contains invalid configuration. ' +
40+
'If you encounter this error within a Qwik project, make sure you have run necessary Nx migrations for qwik-nx plugin.'
4441
);
4542
}
4643

44+
const configurationName = getIntegrationConfigurationName(
45+
IntegrationName.Cloudflare,
46+
config
47+
);
48+
const deployTargetName = config.targets['deploy']
49+
? 'deploy.cloudflare'
50+
: 'deploy';
51+
4752
const normalizedOptions = normalizeOptions(config);
48-
(config.targets['build']?.configurations ?? {})['cloudflare-pages'] = {};
49-
(config.targets['build.ssr'].configurations ??= {})['cloudflare-pages'] =
53+
(config.targets['build']?.configurations ?? {})[configurationName] = {};
54+
(config.targets['build.ssr'].configurations ??= {})[configurationName] =
5055
getBuildSSRTargetCloudflareConfiguration(normalizedOptions);
51-
config.targets['deploy'] = getDeployTarget(normalizedOptions);
52-
config.targets['preview-cloudflare-pages'] =
56+
config.targets[deployTargetName] = getDeployTarget(normalizedOptions);
57+
config.targets['preview-cloudflare'] =
5358
getCloudflarePreviewTarget(normalizedOptions);
54-
config.targets['build-cloudflare-pages'] =
55-
getIntermediateDependsOnTarget(normalizedOptions);
59+
config.targets['build-cloudflare'] = getIntermediateDependsOnTarget(
60+
normalizedOptions,
61+
configurationName
62+
);
5663

5764
updateProjectConfiguration(tree, options.project, config);
5865

@@ -77,7 +84,7 @@ function getDeployTarget(options: NormalizedOptions): TargetConfiguration {
7784
options: {
7885
dist: `dist/${options.projectConfig.root}/client`,
7986
},
80-
dependsOn: ['build-cloudflare-pages'],
87+
dependsOn: ['build-cloudflare'],
8188
};
8289
}
8390

@@ -89,18 +96,19 @@ function getCloudflarePreviewTarget(
8996
options: {
9097
dist: `dist/${options.projectConfig.root}/client`,
9198
},
92-
dependsOn: ['build-cloudflare-pages'],
99+
dependsOn: ['build-cloudflare'],
93100
};
94101
}
95102

96103
/** Currently it's not possible to depend on a target with a specific configuration, that's why intermediate one is required */
97104
function getIntermediateDependsOnTarget(
98-
options: NormalizedOptions
105+
options: NormalizedOptions,
106+
configurationName: string
99107
): TargetConfiguration {
100108
return {
101109
executor: 'nx:run-commands',
102110
options: {
103-
command: `npx nx run ${options.projectConfig.name}:build:cloudflare-pages`,
111+
command: `npx nx run ${options.projectConfig.name}:build:${configurationName}`,
104112
},
105113
};
106114
}

packages/qwik-nx/src/migrations/switch-to-qwik-nx:build-executor/switch-to-qwik-nx:build-executor.spec.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function getSampleProjectJson() {
121121
build: {
122122
executor: 'qwik-nx:build',
123123
options: {
124-
sequence: ['myapp:build.client', 'myapp:build.ssr'],
124+
runSequence: ['myapp:build.client', 'myapp:build.ssr'],
125125
outputPath: 'dist/apps/myapp',
126126
},
127127
},
@@ -247,21 +247,10 @@ function getSampleProjectJson() {
247247
},
248248
serve: {
249249
executor: '@nrwl/vite:dev-server',
250-
defaultConfiguration: 'development',
251250
options: {
252251
buildTarget: 'myapp:build',
253252
mode: 'ssr',
254253
},
255-
configurations: {
256-
development: {
257-
buildTarget: 'myapp:build:development',
258-
hmr: true,
259-
},
260-
production: {
261-
buildTarget: 'myapp:build:production',
262-
hmr: false,
263-
},
264-
},
265254
},
266255
serveDebug: {
267256
executor: 'nx:run-commands',
@@ -311,7 +300,7 @@ function getSampleProjectJson() {
311300
build: {
312301
executor: 'qwik-nx:build',
313302
options: {
314-
sequence: ['myapp:build.client', 'myapp:build.ssr'],
303+
runSequence: ['myapp:build.client', 'myapp:build.ssr'],
315304
outputPath: 'dist/apps/myapp',
316305
},
317306
configurations: {
@@ -361,21 +350,10 @@ function getSampleProjectJson() {
361350
},
362351
serve: {
363352
executor: '@nrwl/vite:dev-server',
364-
defaultConfiguration: 'development',
365353
options: {
366354
buildTarget: 'myapp:build.client',
367355
mode: 'ssr',
368356
},
369-
configurations: {
370-
development: {
371-
buildTarget: 'myapp:build.client:development',
372-
hmr: true,
373-
},
374-
production: {
375-
buildTarget: 'myapp:build.client:production',
376-
hmr: false,
377-
},
378-
},
379357
},
380358
'serve.debug': {
381359
executor: 'nx:run-commands',

0 commit comments

Comments
 (0)