Skip to content

Commit 8612b08

Browse files
authored
fix(openapi-typescript): build cjs support astToString export (#1488)
* fix(openapi-typescript): build cjs support astToString export * test(openapi-typescript): modify unit test
1 parent 310971d commit 8612b08

File tree

2 files changed

+2
-23
lines changed

2 files changed

+2
-23
lines changed

packages/openapi-typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"build": "run-s -s build:*",
4444
"build:clean": "del dist",
4545
"build:esm": "tsc -p tsconfig.build.json",
46-
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:@redocly/ajv --external:@redocly/openapi-core --external:typescript src/index.ts --footer:js=\"module.exports = module.exports.default;\"",
46+
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:@redocly/ajv --external:@redocly/openapi-core --external:typescript src/index.ts",
4747
"dev": "tsc -p tsconfig.build.json --watch",
4848
"download:schemas": "vite-node ./scripts/download-schemas.ts",
4949
"format": "prettier --write \"src/**/*\"",

packages/openapi-typescript/test/cjs.test.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,7 @@
22

33
// important: MUST use require()!
44
const { fileURLToPath } = require("node:url");
5-
const ts = require("typescript");
6-
const openapiTS = require("../dist/index.cjs");
7-
8-
// copy from lib/ts.ts for CJS
9-
function astToString(ast, options) {
10-
const sourceFile = ts.createSourceFile(
11-
options?.fileName ?? "openapi-ts.ts",
12-
options?.sourceText ?? "",
13-
ts.ScriptTarget.ESNext,
14-
false,
15-
ts.ScriptKind.TS,
16-
);
17-
sourceFile.statements = ts.factory.createNodeArray(
18-
Array.isArray(ast) ? ast : [ast],
19-
);
20-
const printer = ts.createPrinter({
21-
newLine: ts.NewLineKind.LineFeed,
22-
removeComments: false,
23-
...options?.formatOptions,
24-
});
25-
return printer.printFile(sourceFile);
26-
}
5+
const { astToString, default: openapiTS } = require('../dist/index.cjs');
276

287
describe("CJS bundle", () => {
298
it("basic", async () => {

0 commit comments

Comments
 (0)