Skip to content

Commit f05033f

Browse files
committed
fix(nx-plugin): fix plugin build output and enhance caching
- fix typo in vitest.config output - change vitest.config to mts for better type support - list vite and vitest as a dep if enabled - change build to only output cjs to support nx plugins - add caching and nx linking if spec file is in another project
1 parent 5558a3b commit f05033f

14 files changed

+207
-121
lines changed

packages/nx-plugin/executors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"executors": {
33
"update-api": {
4-
"implementation": "./dist/updateApi.js",
5-
"schema": "./dist/executors/update-api/schema.json",
4+
"implementation": "./dist/updateApi.cjs",
5+
"schema": "./dist/executors/update-api/updateApi.schema.json",
66
"description": "Updates the OpenAPI spec file and generates new client code if needed."
77
}
88
}

packages/nx-plugin/generators.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.1",
44
"generators": {
55
"openapi-client": {
6-
"factory": "./dist/openapiClient.js",
7-
"schema": "./dist/generators/openapi-client/schema.json",
6+
"factory": "./dist/openapiClient.cjs",
7+
"schema": "./dist/generators/openapi-client/openapiClient.schema.json",
88
"description": "Generate an OpenAPI client library from an OpenAPI spec file."
99
}
1010
}

packages/nx-plugin/package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,28 @@
2525
"nx",
2626
"swagger"
2727
],
28-
"type": "module",
28+
"type": "commonjs",
2929
"main": "./dist/index.cjs",
30-
"module": "./dist/index.js",
30+
"module": "./dist/index.cjs",
3131
"types": "./dist/index.d.ts",
3232
"scripts": {
33-
"build": "tsup && pnpm check-exports",
34-
"check-exports": "attw --pack .",
33+
"build": "tsup",
3534
"test:watch": "vitest watch --config vitest.config.ts",
3635
"test": "vitest run --config vitest.config.ts",
3736
"typecheck": "tsc --noEmit",
3837
"prepublishOnly": "pnpm build"
3938
},
4039
"exports": {
4140
".": {
42-
"import": {
43-
"types": "./dist/index.d.ts",
44-
"default": "./dist/index.js"
45-
},
4641
"require": {
4742
"types": "./dist/index.d.cts",
4843
"default": "./dist/index.cjs"
4944
}
5045
},
5146
"./package.json": "./package.json"
5247
},
53-
"executors": "./dist/executors.json",
54-
"generators": "./dist/generators.json",
48+
"executors": "./executors.json",
49+
"generators": "./generators.json",
5550
"dependencies": {
5651
"@hey-api/json-schema-ref-parser": "1.0.4",
5752
"@hey-api/openapi-ts": "workspace:*",
@@ -67,6 +62,8 @@
6762
"vitest": "3.1.1"
6863
},
6964
"files": [
65+
"executors.json",
66+
"generators.json",
7067
"package.json",
7168
"dist",
7269
"LICENSE.md"

packages/nx-plugin/src/executors/update-api/index.spec.ts renamed to packages/nx-plugin/src/executors/update-api/updateApi.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { type ExecutorContext, logger } from '@nx/devkit';
77
import { randomUUID } from 'crypto';
88
import { afterAll, describe, expect, it, vi } from 'vitest';
99

10-
import generator from '../../generators/openapi-client';
10+
import generator from '../../generators/openapi-client/openapiClient';
1111
import { getGeneratorOptions, TestOptions } from '../../test-utils';
1212
import { CONSTANTS } from '../../vars';
13-
import executor from '.';
1413
import type { UpdateApiExecutorSchema } from './schema';
14+
import executor from './updateApi';
1515

1616
vi.mock('@hey-api/openapi-ts/internal', async (importOriginal) => {
1717
const actual =

packages/nx-plugin/src/executors/update-api/index.ts renamed to packages/nx-plugin/src/executors/update-api/updateApi.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ const runExecutor: PromiseExecutor<UpdateApiExecutorSchema> = async (
160160
logger.info('No changes detected in the API spec.');
161161
if (!force) {
162162
logger.info('Force flag is false. Skipping client code generation.');
163-
await cleanup(absoluteTempFolder);
164163
return { success: true };
165164
} else {
166165
logger.info('Force flag is true. Generating new client code...');
@@ -237,13 +236,13 @@ const runExecutor: PromiseExecutor<UpdateApiExecutorSchema> = async (
237236
});
238237

239238
logger.info('Successfully updated API client and spec files.');
240-
await cleanup(absoluteTempFolder);
241239
return { success: true };
242240
} catch (error) {
243241
const errorMessage = error instanceof Error ? error.message : String(error);
244242
logger.debug(`Error details: ${errorMessage}.`);
245-
await cleanup(absoluteTempFolder);
246243
return { success: false };
244+
} finally {
245+
await cleanup(absoluteTempFolder);
247246
}
248247
};
249248

packages/nx-plugin/src/generators/openapi-client/index.spec.ts renamed to packages/nx-plugin/src/generators/openapi-client/openapiClient.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
88

99
import { getGeneratorOptions } from '../../test-utils';
1010
import { generateClientCode } from '../../utils';
11-
import generator, { updateTsConfig } from './index';
11+
import generator, { updateTsConfig } from './openapiClient';
1212
import {
1313
generateApi,
1414
generateNxProject,
1515
normalizeOptions,
1616
updatePackageJson,
17-
} from './index';
17+
} from './openapiClient';
1818

1919
vi.mock('@hey-api/openapi-ts', async (importOriginal) => {
2020
const actual = await importOriginal<typeof import('@hey-api/openapi-ts')>();
@@ -128,7 +128,7 @@ describe('openapi-client generator', () => {
128128
});
129129
const normalizedOptions = normalizeOptions(options);
130130

131-
generateNxProject({ clientPlugins: {}, normalizedOptions, tree });
131+
await generateNxProject({ clientPlugins: {}, normalizedOptions, tree });
132132

133133
const config = readJson(
134134
tree,
@@ -147,7 +147,7 @@ describe('openapi-client generator', () => {
147147
});
148148
const normalizedOptions = normalizeOptions(options);
149149

150-
generateNxProject({ clientPlugins: {}, normalizedOptions, tree });
150+
await generateNxProject({ clientPlugins: {}, normalizedOptions, tree });
151151

152152
expect(
153153
tree.exists(`${normalizedOptions.projectRoot}/tsconfig.json`),

0 commit comments

Comments
 (0)