Skip to content

Commit

Permalink
build(parser-adapter-json): use nodenext for TypeScript modules (#4454)
Browse files Browse the repository at this point in the history
Refs #4385
  • Loading branch information
glowcloud authored Nov 8, 2024
1 parent 6571168 commit 43ab521
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 40 deletions.
22 changes: 22 additions & 0 deletions packages/apidom-parser-adapter-json/.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-adapter-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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": "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": "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 NODE_NO_WARNINGS=1 mocha",
"perf": "cross-env BABEL_ENV=es babel ./test/perf/index.ts --out-file ./test/perf/index.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/index.mjs",
"perf:lexical-analysis": "cross-env BABEL_ENV=es babel ./test/perf/lexical-analysis.ts --out-file ./test/perf/lexical-analysis.mjs --root-mode 'upward' && cross-env NODE_ENV=test node ./test/perf/lexical-analysis.mjs",
Expand Down
10 changes: 5 additions & 5 deletions packages/apidom-parser-adapter-json/src/adapter-browser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ParseResultElement } from '@swagger-api/apidom-core';

import lexicalAnalysis from './lexical-analysis/browser';
import syntacticAnalysisDirect from './syntactic-analysis/direct';
import syntacticAnalysisIndirect from './syntactic-analysis/indirect';
import { detectionRegExp } from './adapter';
import lexicalAnalysis from './lexical-analysis/browser.ts';
import syntacticAnalysisDirect from './syntactic-analysis/direct/index.ts';
import syntacticAnalysisIndirect from './syntactic-analysis/indirect/index.ts';
import { detectionRegExp } from './adapter.ts';

export { mediaTypes, namespace } from './adapter';
export { mediaTypes, namespace } from './adapter.ts';
export { detectionRegExp };

export {
Expand Down
10 changes: 5 additions & 5 deletions packages/apidom-parser-adapter-json/src/adapter-node.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ParseResultElement } from '@swagger-api/apidom-core';

import lexicalAnalysis from './lexical-analysis/node';
import syntacticAnalysisDirect from './syntactic-analysis/direct';
import syntacticAnalysisIndirect from './syntactic-analysis/indirect';
import { detectionRegExp } from './adapter';
import lexicalAnalysis from './lexical-analysis/node.ts';
import syntacticAnalysisDirect from './syntactic-analysis/direct/index.ts';
import syntacticAnalysisIndirect from './syntactic-analysis/indirect/index.ts';
import { detectionRegExp } from './adapter.ts';

export { mediaTypes, namespace } from './adapter';
export { mediaTypes, namespace } from './adapter.ts';
export { detectionRegExp };

export {
Expand Down
2 changes: 1 addition & 1 deletion packages/apidom-parser-adapter-json/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createNamespace } from '@swagger-api/apidom-core';

export { default as mediaTypes } from './media-types';
export { default as mediaTypes } from './media-types.ts';

export const namespace = createNamespace();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './browser-patch';
import './browser-patch.ts';

import Parser, { Tree } from 'web-tree-sitter';
import { ApiDOMError } from '@swagger-api/apidom-error';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TreeCursor as NodeTreeCursor } from 'tree-sitter';
import { TreeCursor as WebTreeCursor } from 'web-tree-sitter';

import TreeCursorSyntaxNode from './TreeCursorSyntaxNode';
import TreeCursorSyntaxNode from './TreeCursorSyntaxNode.ts';

class TreeCursorIterator {
protected readonly cursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getNodeType as getNodeTypeApiDOM,
} from '@swagger-api/apidom-core';

import CstVisitor from './visitors/CstVisitor';
import TreeCursorIterator from '../TreeCursorIterator';
import CstVisitor from './visitors/CstVisitor.ts';
import TreeCursorIterator from '../TreeCursorIterator.ts';

const keyMap = {
document: ['children'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isPrimitiveElement,
} from '@swagger-api/apidom-core';

import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode';
import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode.ts';

/* eslint-disable no-underscore-dangle */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Tree as WebTree } from 'web-tree-sitter';
import { ParseResultElement } from '@swagger-api/apidom-core';
import { visit } from '@swagger-api/apidom-ast';

import TreeCursorIterator from '../TreeCursorIterator';
import CstVisitor, { keyMap as cstKeyMap } from './visitors/CstVisitor';
import TreeCursorIterator from '../TreeCursorIterator.ts';
import CstVisitor, { keyMap as cstKeyMap } from './visitors/CstVisitor.ts';
import JsonAstVisitor, {
keyMap as astKeyMap,
isNode,
getNodeType,
} from './visitors/JsonAstVisitor';
} from './visitors/JsonAstVisitor.ts';

type Tree = WebTree | NodeTree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Error,
} from '@swagger-api/apidom-ast';

import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode';
import TreeCursorSyntaxNode from '../../TreeCursorSyntaxNode.ts';

export const keyMap = {
document: ['children'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
import { expect, assert } from 'chai';
import { sexprs, isObjectElement, isParseResultElement } from '@swagger-api/apidom-core';

import * as adapter from '../src/adapter-browser';
import * as adapter from '../src/adapter-browser.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample-data.json')).toString();
Expand Down
2 changes: 1 addition & 1 deletion packages/apidom-parser-adapter-json/test/adapter-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url';
import { expect, assert } from 'chai';
import { sexprs, toJSON, isObjectElement, isParseResultElement } from '@swagger-api/apidom-core';

import * as adapter from '../src/adapter-node';
import * as adapter from '../src/adapter-node.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample-data.json')).toString();
Expand Down
2 changes: 1 addition & 1 deletion packages/apidom-parser-adapter-json/test/media-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from 'chai';
import ApiDOMParser from '@swagger-api/apidom-parser';

import * as jsonAdapter from '../src/adapter-node';
import * as jsonAdapter from '../src/adapter-node.ts';

describe('given adapter is used in parser', function () {
const parser = new ApiDOMParser().use(jsonAdapter);
Expand Down
4 changes: 2 additions & 2 deletions packages/apidom-parser-adapter-json/test/mocha-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { jestSnapshotPlugin, addSerializer } from 'mocha-chai-jest-snapshot';
import jsdomGlobal from 'jsdom-global';

// @ts-ignore
import * as jestApiDOMSerializer from '../../../scripts/jest-serializer-apidom';
import * as jestApiDOMSerializer from '../../../scripts/jest-serializer-apidom.mjs';
// @ts-ignore
import * as jestStringSerializer from '../../../scripts/jest-serializer-string';
import * as jestStringSerializer from '../../../scripts/jest-serializer-string.mjs';

/**
* Configure snapshot testing.
Expand Down
6 changes: 3 additions & 3 deletions packages/apidom-parser-adapter-json/test/perf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import Benchmark from 'benchmark';
import type { Event } from 'benchmark';

import lexicalAnalysisBench from './lexical-analysis';
import parseSyntacticAnalysisDirectBench from './parse-syntactic-analysis-direct';
import parseSyntacticAnalysisIndirectBench from './parse-syntactic-analysis-indirect';
import lexicalAnalysisBench from './lexical-analysis.ts';
import parseSyntacticAnalysisDirectBench from './parse-syntactic-analysis-direct.ts';
import parseSyntacticAnalysisIndirectBench from './parse-syntactic-analysis-indirect.ts';

const suite = new Benchmark.Suite();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
import Benchmark from 'benchmark';
import type { Deferred } from 'benchmark';

import analyze from '../../src/lexical-analysis/node';
import analyze from '../../src/lexical-analysis/node.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturePath = path.join(__dirname, 'fixtures/data.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
import Benchmark, { Deferred } from 'benchmark';

import { parse } from '../../src/adapter-node';
import { parse } from '../../src/adapter-node.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturePath = path.join(__dirname, 'fixtures/data.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
import Benchmark from 'benchmark';
import type { Event, Deferred } from 'benchmark';

import { parse } from '../../src/adapter-node';
import { parse } from '../../src/adapter-node.ts';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixturePath = path.join(__dirname, 'fixtures/data.json');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import { lexicalAnalysis } from '../../src/adapter-node';
import TreeCursorIterator from '../../src/syntactic-analysis/TreeCursorIterator';
import { lexicalAnalysis } from '../../src/adapter-node.ts';
import TreeCursorIterator from '../../src/syntactic-analysis/TreeCursorIterator.ts';

describe('syntactic-analysis', function () {
context('TreeCursorIterator', function () {
Expand Down
10 changes: 10 additions & 0 deletions packages/apidom-parser-adapter-json/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-adapter-json/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 43ab521

Please sign in to comment.