Skip to content

Commit 2c55723

Browse files
authored
Merge pull request #591 from eemeli/import-ts
Use .ts extension in relative source imports
2 parents 715e8ed + ab240c1 commit 2c55723

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+664
-530
lines changed

.github/workflows/deno.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deno
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
deno-version: [v1.x, v2.x]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with: { submodules: true }
21+
- uses: denoland/setup-deno@v2
22+
with:
23+
deno-version: ${{ matrix.deno-version }}
24+
- run: deno src/public-api.ts

config/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ switch (process.env.npm_lifecycle_event) {
2727
'^yaml$': '<rootDir>/dist/index.js',
2828
'^yaml/cli$': '<rootDir>/dist/cli.mjs',
2929
'^yaml/util$': '<rootDir>/dist/util.js',
30-
'^../src/test-events$': '<rootDir>/dist/test-events.js'
30+
'^../src/test-events.ts$': '<rootDir>/dist/test-events.js'
3131
}
3232
transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = babel
3333
break

config/rollup.node-config.mjs

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
11
import typescript from '@rollup/plugin-typescript'
2+
import * as ts from 'typescript'
3+
4+
/**
5+
* Drop .ts extension from import & export paths in .d.ts files
6+
* to support older TS versions.
7+
*
8+
* @param {ts.TransformationContext} context
9+
*/
10+
function fixDeclarationImportPaths(context) {
11+
/** @param {ts.SourceFile} source */
12+
return function fixPaths(source) {
13+
/** @param {ts.Node} node */
14+
function visitor(node) {
15+
if (ts.isStringLiteral(node) && /^\.+\/.*\.ts$/.test(node.text)) {
16+
return ts.factory.createStringLiteral(node.text.slice(0, -3), true)
17+
}
18+
return ts.visitEachChild(node, visitor, context)
19+
}
20+
return ts.visitNode(source, visitor)
21+
}
22+
}
23+
24+
/**
25+
* Strip out TS relative import path rewrite helper from dynamic import() calls
26+
*
27+
* Required due to
28+
* https://github.com/rollup/plugins/issues/1820
29+
*
30+
* @param {ts.TransformationContext} context
31+
*/
32+
function fixDynamicImportRewrite(context) {
33+
/** @param {ts.SourceFile} source */
34+
return function fixDynamicImport(source) {
35+
/** @param {ts.Node} node */
36+
function visitor(node) {
37+
if (
38+
ts.isCallExpression(node) &&
39+
ts.isIdentifier(node.expression) &&
40+
String(node.expression.escapedText) ===
41+
'___rewriteRelativeImportExtension' &&
42+
node.arguments.length === 1
43+
) {
44+
return node.arguments[0]
45+
}
46+
return ts.visitEachChild(node, visitor, context)
47+
}
48+
return ts.visitNode(source, visitor)
49+
}
50+
}
251

352
export default [
453
{
@@ -13,13 +62,22 @@ export default [
1362
esModule: false,
1463
preserveModules: true
1564
},
16-
plugins: [typescript()],
65+
plugins: [
66+
typescript({
67+
transformers: { afterDeclarations: [fixDeclarationImportPaths] }
68+
})
69+
],
1770
treeshake: { moduleSideEffects: false, propertyReadSideEffects: false }
1871
},
1972
{
2073
input: 'src/cli.ts',
2174
output: { file: 'dist/cli.mjs' },
2275
external: () => true,
23-
plugins: [typescript()]
76+
plugins: [
77+
typescript({
78+
declaration: false,
79+
transformers: { after: [fixDynamicImportRewrite] }
80+
})
81+
]
2482
}
2583
]

eslint.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,25 @@ export default [
3838
'no-control-regex': 'off',
3939
'no-fallthrough': ['error', { commentPattern: 'fallthrough' }],
4040
'no-implicit-globals': 'error',
41+
'no-restricted-imports': [
42+
'error',
43+
{
44+
patterns: [
45+
{
46+
regex: '^\\..*(?<!\\.ts)$',
47+
message: 'Relative imports must use .ts extension.'
48+
}
49+
]
50+
}
51+
],
4152
'no-template-curly-in-string': 'warn',
4253
'no-var': 'error',
4354
'prefer-const': ['warn', { destructuring: 'all' }],
55+
'@typescript-eslint/consistent-type-exports': 'error',
56+
'@typescript-eslint/consistent-type-imports': [
57+
'error',
58+
{ fixStyle: 'separate-type-imports' }
59+
],
4460
'@typescript-eslint/no-explicit-any': 'off',
4561
'@typescript-eslint/no-namespace': 'off',
4662
'@typescript-eslint/no-unsafe-argument': 'off',

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@eslint/js": "^9.9.1",
7575
"@rollup/plugin-babel": "^6.0.3",
7676
"@rollup/plugin-replace": "^5.0.2",
77-
"@rollup/plugin-typescript": "^11.0.0",
77+
"@rollup/plugin-typescript": "^12.1.1",
7878
"@types/jest": "^29.2.4",
7979
"@types/node": "^20.11.20",
8080
"babel-jest": "^29.0.1",
@@ -86,8 +86,8 @@
8686
"jest-ts-webcompat-resolver": "^1.0.0",
8787
"prettier": "^3.0.2",
8888
"rollup": "^4.12.0",
89-
"tslib": "^2.1.0",
90-
"typescript": "^5.0.3",
89+
"tslib": "^2.8.1",
90+
"typescript": "^5.7.2",
9191
"typescript-eslint": "^8.4.0"
9292
},
9393
"engines": {

src/cli.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { resolve } from 'node:path'
22
import { parseArgs } from 'node:util'
33

4-
import { type Token, prettyToken } from './parse/cst.js'
5-
import { Lexer } from './parse/lexer.js'
6-
import { Parser } from './parse/parser.js'
7-
import { Composer } from './compose/composer.js'
8-
import { LineCounter } from './parse/line-counter.js'
9-
import { type Document } from './doc/Document.js'
10-
import { prettifyError } from './errors.js'
11-
import { visit, type visitor } from './visit.js'
4+
import type { Token } from './parse/cst.ts'
5+
import { prettyToken } from './parse/cst.ts'
6+
import { Lexer } from './parse/lexer.ts'
7+
import { Parser } from './parse/parser.ts'
8+
import { Composer } from './compose/composer.ts'
9+
import { LineCounter } from './parse/line-counter.ts'
10+
import type { Document } from './doc/Document.ts'
11+
import { prettifyError } from './errors.ts'
12+
import type { visitor } from './visit.ts'
13+
import { visit } from './visit.ts'
1214

1315
export const help = `\
1416
yaml: A command-line YAML processor and inspector

src/compose/compose-collection.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { isNode } from '../nodes/identity.js'
2-
import type { ParsedNode } from '../nodes/Node.js'
3-
import { Scalar } from '../nodes/Scalar.js'
4-
import { YAMLMap } from '../nodes/YAMLMap.js'
5-
import { YAMLSeq } from '../nodes/YAMLSeq.js'
1+
import { isNode } from '../nodes/identity.ts'
2+
import type { ParsedNode } from '../nodes/Node.ts'
3+
import { Scalar } from '../nodes/Scalar.ts'
4+
import { YAMLMap } from '../nodes/YAMLMap.ts'
5+
import { YAMLSeq } from '../nodes/YAMLSeq.ts'
66
import type {
77
BlockMap,
88
BlockSequence,
99
FlowCollection,
1010
SourceToken
11-
} from '../parse/cst.js'
12-
import { CollectionTag } from '../schema/types.js'
13-
import type { ComposeContext, ComposeNode } from './compose-node.js'
14-
import type { ComposeErrorHandler } from './composer.js'
15-
import { resolveBlockMap } from './resolve-block-map.js'
16-
import { resolveBlockSeq } from './resolve-block-seq.js'
17-
import { resolveFlowCollection } from './resolve-flow-collection.js'
11+
} from '../parse/cst.ts'
12+
import type { CollectionTag } from '../schema/types.ts'
13+
import type { ComposeContext, ComposeNode } from './compose-node.ts'
14+
import type { ComposeErrorHandler } from './composer.ts'
15+
import { resolveBlockMap } from './resolve-block-map.ts'
16+
import { resolveBlockSeq } from './resolve-block-seq.ts'
17+
import { resolveFlowCollection } from './resolve-flow-collection.ts'
1818

1919
function resolveCollection(
2020
CN: ComposeNode,

src/compose/compose-doc.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import type { Directives } from '../doc/directives.js'
2-
import { Document } from '../doc/Document.js'
3-
import type { ParsedNode } from '../nodes/Node.js'
1+
import type { Directives } from '../doc/directives.ts'
2+
import { Document } from '../doc/Document.ts'
3+
import type { ParsedNode } from '../nodes/Node.ts'
44
import type {
55
DocumentOptions,
66
ParseOptions,
77
SchemaOptions
8-
} from '../options.js'
9-
import type * as CST from '../parse/cst.js'
8+
} from '../options.ts'
9+
import type * as CST from '../parse/cst.ts'
1010
import {
11-
ComposeContext,
11+
type ComposeContext,
1212
composeEmptyNode,
1313
composeNode
14-
} from './compose-node.js'
15-
import type { ComposeErrorHandler } from './composer.js'
16-
import { resolveEnd } from './resolve-end.js'
17-
import { resolveProps } from './resolve-props.js'
14+
} from './compose-node.ts'
15+
import type { ComposeErrorHandler } from './composer.ts'
16+
import { resolveEnd } from './resolve-end.ts'
17+
import { resolveProps } from './resolve-props.ts'
1818

1919
export function composeDoc<
2020
Contents extends ParsedNode = ParsedNode,

src/compose/compose-node.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { Directives } from '../doc/directives.js'
2-
import { Alias } from '../nodes/Alias.js'
3-
import { isScalar } from '../nodes/identity.js'
4-
import type { ParsedNode } from '../nodes/Node.js'
5-
import type { ParseOptions } from '../options.js'
6-
import type { FlowScalar, SourceToken, Token } from '../parse/cst.js'
7-
import type { Schema } from '../schema/Schema.js'
8-
import { composeCollection } from './compose-collection.js'
9-
import { composeScalar } from './compose-scalar.js'
10-
import type { ComposeErrorHandler } from './composer.js'
11-
import { resolveEnd } from './resolve-end.js'
12-
import { emptyScalarPosition } from './util-empty-scalar-position.js'
1+
import type { Directives } from '../doc/directives.ts'
2+
import { Alias } from '../nodes/Alias.ts'
3+
import { isScalar } from '../nodes/identity.ts'
4+
import type { ParsedNode } from '../nodes/Node.ts'
5+
import type { ParseOptions } from '../options.ts'
6+
import type { FlowScalar, SourceToken, Token } from '../parse/cst.ts'
7+
import type { Schema } from '../schema/Schema.ts'
8+
import { composeCollection } from './compose-collection.ts'
9+
import { composeScalar } from './compose-scalar.ts'
10+
import type { ComposeErrorHandler } from './composer.ts'
11+
import { resolveEnd } from './resolve-end.ts'
12+
import { emptyScalarPosition } from './util-empty-scalar-position.ts'
1313

1414
export interface ComposeContext {
1515
atKey: boolean

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy