Skip to content

Commit ad1e02f

Browse files
committed
Update async-cli package to use ES modules
Fixes #1698 Update `async-cli` package to use ES modules instead of CommonJS. * **Update `tsconfig.json` files:** - Change `module` to `ESNext` in `tsconfig.json`, `assets/create-glee-app/templates/default/tsconfig.json`, and `assets/create-glee-app/templates/tutorial/tsconfig.json`. - Update `moduleResolution` to `node` in the same files. * **Update `package.json`:** - Add `"type": "module"`. * **Update import/export syntax:** - Modify import statements in `src/commands/bundle.ts`, `src/commands/convert.ts`, `src/commands/generate/fromTemplate.ts`, `scripts/fetch-asyncapi-example.js`, `scripts/releasePackagesRename.js`, and `src/index.ts` to use ES module syntax.
1 parent 819b585 commit ad1e02f

File tree

10 files changed

+33
-40
lines changed

10 files changed

+33
-40
lines changed

assets/create-glee-app/templates/default/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"target": "es6",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
7-
"module": "commonjs",
7+
"module": "ESNext",
88
"skipLibCheck": true
99
}
1010
}

assets/create-glee-app/templates/tutorial/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"target": "es6",
55
"esModuleInterop": true,
66
"moduleResolution": "node",
7-
"module": "commonjs"
7+
"module": "ESNext"
88
}
9-
}
9+
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,6 @@
172172
"action:docker:build": "docker build -f github-action/Dockerfile -t asyncapi/github-action-for-cli:latest .",
173173
"action:test": "cd github-action && make test"
174174
},
175-
"types": "lib/index.d.ts"
175+
"types": "lib/index.d.ts",
176+
"type": "module"
176177
}

scripts/fetch-asyncapi-example.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
2-
3-
const fs = require('fs');
4-
const unzipper = require('unzipper');
5-
const path = require('path');
6-
7-
const { Parser } = require('@asyncapi/parser/cjs');
8-
const { AvroSchemaParser } = require('@asyncapi/avro-schema-parser');
9-
const { OpenAPISchemaParser } = require('@asyncapi/openapi-schema-parser');
10-
const { RamlDTSchemaParser } = require('@asyncapi/raml-dt-schema-parser');
11-
const { pipeline } = require('stream');
12-
const { promisify } = require('util');
1+
import fs from 'fs';
2+
import unzipper from 'unzipper';
3+
import path from 'path';
4+
import { Parser } from '@asyncapi/parser';
5+
import { AvroSchemaParser } from '@asyncapi/avro-schema-parser';
6+
import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';
7+
import { RamlDTSchemaParser } from '@asyncapi/raml-dt-schema-parser';
8+
import { pipeline } from 'stream';
9+
import { promisify } from 'util';
1310

1411
const streamPipeline = promisify(pipeline);
1512

scripts/releasePackagesRename.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
1+
import { rename, access, mkdir } from 'fs/promises';
2+
import packageJson from '../package.json';
3+
import path from 'path';
4+
import simpleGit from 'simple-git';
25

3-
const { rename, access, mkdir } = require('fs').promises;
4-
const packageJson = require('../package.json');
5-
const path = require('path');
6-
const simpleGit = require('simple-git');
7-
const git = simpleGit({baseDir: process.cwd()});
6+
const git = simpleGit({ baseDir: process.cwd() });
87

98
async function fileExists(checkPath) {
109
try {
@@ -28,7 +27,7 @@ async function createDirectory(directoryPath) {
2827
}
2928
}
3029

31-
async function renameDeb({version, name, sha}) {
30+
async function renameDeb({ version, name, sha }) {
3231
const dist = 'dist/deb';
3332

3433
// deb package naming convention: https://github.com/oclif/oclif/blob/fb5da961f925fa0eba5c5b05c8cee0c9bd156c00/src/upload-util.ts#L51
@@ -37,7 +36,7 @@ async function renameDeb({version, name, sha}) {
3736
await checkAndRenameFile(generatedPath, newPath);
3837
}
3938

40-
async function renameTar({version, name, sha}) {
39+
async function renameTar({ version, name, sha }) {
4140
const dist = 'dist';
4241

4342
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-linux-x64.tar.gz`);
@@ -49,15 +48,15 @@ async function renameTar({version, name, sha}) {
4948
await checkAndRenameFile(generatedPath, newPath);
5049
}
5150

52-
async function renameWindows({version, name, sha, arch}) {
51+
async function renameWindows({ version, name, sha, arch }) {
5352
const dist = 'dist/win32';
5453

5554
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.exe`);
5655
const newPath = path.resolve(dist, `asyncapi.${arch}.exe`);
5756
await checkAndRenameFile(generatedPath, newPath);
5857
}
5958

60-
async function renamePkg({version, name, sha, arch}) {
59+
async function renamePkg({ version, name, sha, arch }) {
6160
const dist = 'dist/macos';
6261

6362
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.pkg`);
@@ -69,12 +68,12 @@ async function renamePackages() {
6968
const version = packageJson.version;
7069
const name = 'asyncapi';
7170
const sha = await git.revparse(['--short', 'HEAD']);
72-
await renameDeb({version: version.split('-')[0], name, sha});
73-
await renamePkg({version, name, sha, arch: 'x64'});
74-
await renamePkg({version, name, sha, arch: 'arm64'});
75-
await renameWindows({version, name, sha, arch: 'x64'});
76-
await renameWindows({version, name, sha, arch: 'x86'});
77-
await renameTar({version, name, sha});
71+
await renameDeb({ version: version.split('-')[0], name, sha });
72+
await renamePkg({ version, name, sha, arch: 'x64' });
73+
await renamePkg({ version, name, sha, arch: 'arm64' });
74+
await renameWindows({ version, name, sha, arch: 'x64' });
75+
await renameWindows({ version, name, sha, arch: 'x86' });
76+
await renameTar({ version, name, sha });
7877
}
7978

8079
renamePackages();

src/commands/bundle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Command from '../core/base';
22
import bundle from '@asyncapi/bundler';
3-
import { promises } from 'fs';
3+
import { promises as fsPromises } from 'fs';
44
import path from 'path';
55
import { Specification } from '../core/models/SpecificationFile';
66
import { Document } from '@asyncapi/bundler/lib/document';
77
import { bundleFlags } from '../core/flags/bundle.flags';
88

9-
const { writeFile } = promises;
9+
const { writeFile } = fsPromises;
1010

1111
export default class Bundle extends Command {
1212
static readonly description = 'Bundle one or multiple AsyncAPI Documents and their references together.';

src/commands/convert.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-ts-comment */
21
import { promises as fPromises } from 'fs';
32
import { Args } from '@oclif/core';
43
import Command from '../core/base';
@@ -9,7 +8,6 @@ import { convert, convertOpenAPI, convertPostman } from '@asyncapi/converter';
98
import type { AsyncAPIConvertVersion, OpenAPIConvertVersion } from '@asyncapi/converter';
109
import { cyan, green } from 'picocolors';
1110
import { proxyFlags } from '../core/flags/proxy.flags';
12-
// @ts-ignore
1311
import specs from '@asyncapi/specs';
1412
import { convertFlags } from '../core/flags/convert.flags';
1513

src/commands/generate/fromTemplate.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Args } from '@oclif/core';
22
import Command from '../../core/base';
3-
// eslint-disable-next-line
4-
// @ts-ignore
53
import AsyncAPIGenerator from '@asyncapi/generator';
64
import AsyncAPINewGenerator from 'generator-v2';
75
import path from 'path';

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { run } from '@oclif/core';
1+
import { run } from '@oclif/core';
22

33
/**
44
* For NodeJS < 15, unhandled rejections are treated as warnings.

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"outDir": "./lib",
44
"baseUrl": "./src",
55
"target": "es6",
6-
"module": "commonjs",
6+
"module": "ESNext",
77
"lib": [
88
"esnext",
99
],

0 commit comments

Comments
 (0)