Skip to content

Commit

Permalink
build(parser): use nodenext for TypeScript modules (#4456)
Browse files Browse the repository at this point in the history
Refs #4385
  • Loading branch information
glowcloud authored Nov 11, 2024
1 parent e5361e8 commit f771158
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 13 deletions.
22 changes: 22 additions & 0 deletions packages/apidom-parser/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"settings": {
"import/resolver": {
"typescript": {
"project": ["./tsconfig.json"]
}
}
},
"rules": {
"import/extensions": [
"error",
"always",
{
"ts": "always",
"tsx": "always",
"js": "always",
"jsx": "never",
"ignorePackages": true
}
]
}
}
4 changes: 2 additions & 2 deletions packages/apidom-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"lint": "eslint ./",
"lint:fix": "eslint ./ --fix",
"clean": "rimraf --glob 'src/**/*.mjs' 'src/**/*.cjs' 'test/**/*.mjs' ./dist ./types",
"typescript:check-types": "tsc --noEmit",
"typescript:declaration": "copyfiles -u 1 'src/**/*.d.ts' ./types && tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js",
"typescript:check-types": "tsc --noEmit && tsc -p ./test/tsconfig.json --noEmit",
"typescript:declaration": "copyfiles -u 1 'src/**/*.d.ts' ./types && tsc -p tsconfig.declaration.json && rollup -c config/rollup/types.dist.js",
"test": "npm run build:es && cross-env BABEL_ENV=es babel test --out-dir test --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward' && cross-env NODE_ENV=test mocha",
"prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .",
"postpack": "rimraf NOTICE LICENSES"
Expand Down
2 changes: 1 addition & 1 deletion packages/apidom-parser/src/errors/ParserError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiDOMStructuredError, ApiDOMErrorOptions } from '@swagger-api/apidom-error';

import { ApiDOMParserOptions } from '../types';
import type { ApiDOMParserOptions } from '../types.d.ts';

interface ParserErrorOptions extends ApiDOMErrorOptions {
readonly source: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/apidom-parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { head } from 'ramda';
import { isArray, isFunction, isString, isUndefined } from 'ramda-adjunct';
import { MediaTypes, Namespace, ParseResultElement } from '@swagger-api/apidom-core';

import ParserError from './errors/ParserError';
import { ApiDOMParserOptions, ApiDOMParserAdapter } from './types';
import ParserError from './errors/ParserError.ts';
import type { ApiDOMParserOptions, ApiDOMParserAdapter } from './types.d.ts';

export type { ApiDOMParserOptions, ApiDOMParserAdapter } from './types';
export type { ApiDOMParserOptions, ApiDOMParserAdapter } from './types.d.ts';

export { ParserError };

Expand Down
2 changes: 1 addition & 1 deletion packages/apidom-parser/test/adapter-priority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as asyncApiJsonAdapterModule from '@swagger-api/apidom-parser-adapter-a
import * as asyncApiYamlAdapterModule from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2';
import { isAsyncApi2Element } from '@swagger-api/apidom-ns-asyncapi-2';

import ApiDOMParser from '../src/parser';
import ApiDOMParser from '../src/parser.ts';

const parser = new ApiDOMParser();
const asyncApiJsonAdapter = { ...asyncApiJsonAdapterModule };
Expand Down
2 changes: 1 addition & 1 deletion packages/apidom-parser/test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isOpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1';
import * as openapi3_1Adapter from '@swagger-api/apidom-parser-adapter-openapi-json-3-1';
import * as yamlAdapter from '@swagger-api/apidom-parser-adapter-yaml-1-2';

import ApiDOMParser, { ParserError } from '../src/parser';
import ApiDOMParser, { ParserError } from '../src/parser.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample-api.json')).toString();
Expand Down
10 changes: 10 additions & 0 deletions packages/apidom-parser/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node"
},
"include": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": [
"test/**/*"
],
"compilerOptions": {
"declaration": true,
"declarationDir": "types",
Expand Down
8 changes: 6 additions & 2 deletions packages/apidom-parser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"allowImportingTsExtensions": true
},
"include": [
"src/**/*",
"test/**/*"
"src/**/*"
]
}

0 comments on commit f771158

Please sign in to comment.