Skip to content

Commit

Permalink
feat: add "type": "module" as default,for support esm
Browse files Browse the repository at this point in the history
  • Loading branch information
liangskyli committed Dec 11, 2023
1 parent 4a8f629 commit 1a5cea5
Show file tree
Hide file tree
Showing 21 changed files with 2,041 additions and 5,457 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "git",
"url": "git+https://github.com/liangskyli/openapi-ts.git"
},
"type": "module",
"scripts": {
"build": "lerna run build",
"test": "lerna run test",
Expand All @@ -24,7 +25,7 @@
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"prettier --write",
"node script/lint"
"node script/lint.cjs"
]
},
"devDependencies": {
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/openapi-gen-ts/bin/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node
const { commandCodeGenCli } = require('../lib/index.cjs');
const { version } = require('../package.json');

commandCodeGenCli(version);
6 changes: 5 additions & 1 deletion packages/openapi-gen-ts/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node
const { commandCodeGenCli } = require('../lib/index.cjs');
import { createRequire } from 'node:module';
import { commandCodeGenCli } from '../lib/index.js';

const require = createRequire(import.meta.url);

const { version } = require('../package.json');

commandCodeGenCli(version);
19 changes: 14 additions & 5 deletions packages/openapi-gen-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
"openapi generate typescript defenitions",
"openapi generate request api file"
],
"main": "./lib/index.cjs.js",
"module": "./lib/index.esm.js",
"type": "module",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"typings": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
}
},
"files": [
"lib",
"bin",
Expand All @@ -24,7 +32,8 @@
"package.json"
],
"bin": {
"openapi-gen-ts": "bin/index.js"
"openapi-gen-ts": "bin/index.js",
"openapi-gen-ts-cjs": "bin/index.cjs"
},
"repository": {
"type": "git",
Expand All @@ -34,11 +43,11 @@
"test": "vitest run",
"test-u": "vitest -u run",
"coverage": "vitest run --coverage",
"build": "rollup --bundleConfigAsCjs --config=./rollup.config.js",
"build": "rollup --config=./rollup.config.js",
"update:deps": "pnpm update --interactive --latest"
},
"dependencies": {
"@liangskyli/utils": "^3.0.1",
"@liangskyli/utils": "^3.2.0-beta.0",
"axios": "^1.6.2",
"commander": "^11.1.0",
"fs-extra": "^11.2.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/openapi-gen-ts/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getConfig } from '../rollup.base.config';
import packageJSON from './package.json';
import { createRequire } from 'node:module';
import { getConfig } from '../rollup.base.config.js';

const require = createRequire(import.meta.url);
const packageJSON = require('./package.json');

export default [getConfig(packageJSON)];
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/src/gen/file/gen-interface-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { fileTip, writePrettierFile } from '../../utils';
import type {
IGenInterfaceRequestFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/src/gen/file/gen-request-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { fileTip, writePrettierFile } from '../../utils';
import type {
IGenInterfaceRequestFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/src/gen/file/gen-request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IPrettierOptions } from '@liangskyli/utils';
import path from 'path';
import path from 'node:path';
import { fileTip, packageName, writePrettierFile } from '../../utils';

export type IGenRequestOpts = {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/src/gen/file/gen-schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IPrettierOptions } from '@liangskyli/utils';
import { copyOptions } from '@liangskyli/utils';
import path from 'path';
import path from 'node:path';
import type { PartialArgs } from 'typescript-json-schema';
import * as TJS from 'typescript-json-schema';
import { writePrettierFile } from '../../utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/src/gen/file/gen-ts-schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IPrettierOptions } from '@liangskyli/utils';
import path from 'node:path';
import openapiTS from 'openapi-typescript';
import path from 'path';
import type * as TJS from 'typescript-json-schema';
import { fileTip, writePrettierFile } from '../../utils';
import type { IGenTsDataOpts } from '../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/src/gen/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { colors, getAbsolutePath, removeFilesSync } from '@liangskyli/utils';
import fs from 'fs-extra';
import path from 'path';
import path from 'node:path';
import type { IGeneratorFile } from './generator-file';
import { generatorFile } from './generator-file';
import { swagger2ToOpenapi } from './swagger2-to-openapi';
Expand Down
18 changes: 17 additions & 1 deletion packages/openapi-gen-ts/test/cli/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`CLI > CLI test 1`] = `
exports[`CLI > CLI test cjs 1`] = `
"use configFile path: ./test/cli/request.config.ts
Clean schema-api dir: test/all-gen-dirs/gen-ts-dir-cli1/schema-api
Generate schema-api/ts-schema.ts success
Generate schema-api/schema.json success
Generate schema-api/request.ts file success
Generate schema-api/interface-api.ts file success
Generate schema-api/request-api.ts file success
Clean schema-api dir: test/all-gen-dirs/gen-ts-dir-cli2/schema-api
Generate schema-api/ts-schema.ts success
Generate schema-api/schema.json success
Generate schema-api/request.ts file success
Generate schema-api/interface-api.ts file success
Generate schema-api/request-api.ts file success"
`;

exports[`CLI > CLI test esm 1`] = `
"use configFile path: ./test/cli/request.config.ts
Clean schema-api dir: test/all-gen-dirs/gen-ts-dir-cli1/schema-api
Generate schema-api/ts-schema.ts success
Expand Down
13 changes: 12 additions & 1 deletion packages/openapi-gen-ts/test/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { describe, expect, test } from 'vitest';
const cwd = new URL('../../', import.meta.url);
const cmd = 'node';
describe('CLI', () => {
test('CLI test', async () => {
test('CLI test esm', async () => {
const { stdout } = await execa(
cmd,
['./bin/index.js', '-c', './test/cli/request.config.ts'],
Expand All @@ -16,4 +16,15 @@ describe('CLI', () => {
);
await expect(winPath(stdout)).toMatchSnapshot();
});

test('CLI test cjs', async () => {
const { stdout } = await execa(
cmd,
['./bin/index.cjs', '-c', './test/cli/request.config.ts'],
{
cwd,
},
);
await expect(winPath(stdout)).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/test/cli/request.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from '../../lib/index.esm';
import { defineConfig } from '../../lib/index.js';

export default defineConfig([
{
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-gen-ts/test/gen/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs-extra';
import path from 'path';
import path from 'node:path';
import { beforeEach, describe, expect, test, vi } from 'vitest';
import genTsData from '../../src/gen';

Expand Down
Loading

0 comments on commit 1a5cea5

Please sign in to comment.