diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml new file mode 100644 index 00000000..038e853d --- /dev/null +++ b/.github/workflows/deno.yml @@ -0,0 +1,24 @@ +name: Deno + +on: + pull_request: + branches: [main] + push: + branches: [main] + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + deno-version: [v1.x, v2.x] + + steps: + - uses: actions/checkout@v4 + with: { submodules: true } + - uses: denoland/setup-deno@v2 + with: + deno-version: ${{ matrix.deno-version }} + - run: deno src/public-api.ts diff --git a/config/jest.config.js b/config/jest.config.js index a63616c1..57f878c9 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -27,7 +27,7 @@ switch (process.env.npm_lifecycle_event) { '^yaml$': '/dist/index.js', '^yaml/cli$': '/dist/cli.mjs', '^yaml/util$': '/dist/util.js', - '^../src/test-events$': '/dist/test-events.js' + '^../src/test-events.ts$': '/dist/test-events.js' } transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = babel break diff --git a/config/rollup.node-config.mjs b/config/rollup.node-config.mjs index ee79df1d..1367bdac 100644 --- a/config/rollup.node-config.mjs +++ b/config/rollup.node-config.mjs @@ -1,4 +1,53 @@ import typescript from '@rollup/plugin-typescript' +import * as ts from 'typescript' + +/** + * Drop .ts extension from import & export paths in .d.ts files + * to support older TS versions. + * + * @param {ts.TransformationContext} context + */ +function fixDeclarationImportPaths(context) { + /** @param {ts.SourceFile} source */ + return function fixPaths(source) { + /** @param {ts.Node} node */ + function visitor(node) { + if (ts.isStringLiteral(node) && /^\.+\/.*\.ts$/.test(node.text)) { + return ts.factory.createStringLiteral(node.text.slice(0, -3), true) + } + return ts.visitEachChild(node, visitor, context) + } + return ts.visitNode(source, visitor) + } +} + +/** + * Strip out TS relative import path rewrite helper from dynamic import() calls + * + * Required due to + * https://github.com/rollup/plugins/issues/1820 + * + * @param {ts.TransformationContext} context + */ +function fixDynamicImportRewrite(context) { + /** @param {ts.SourceFile} source */ + return function fixDynamicImport(source) { + /** @param {ts.Node} node */ + function visitor(node) { + if ( + ts.isCallExpression(node) && + ts.isIdentifier(node.expression) && + String(node.expression.escapedText) === + '___rewriteRelativeImportExtension' && + node.arguments.length === 1 + ) { + return node.arguments[0] + } + return ts.visitEachChild(node, visitor, context) + } + return ts.visitNode(source, visitor) + } +} export default [ { @@ -13,13 +62,22 @@ export default [ esModule: false, preserveModules: true }, - plugins: [typescript()], + plugins: [ + typescript({ + transformers: { afterDeclarations: [fixDeclarationImportPaths] } + }) + ], treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } }, { input: 'src/cli.ts', output: { file: 'dist/cli.mjs' }, external: () => true, - plugins: [typescript()] + plugins: [ + typescript({ + declaration: false, + transformers: { after: [fixDynamicImportRewrite] } + }) + ] } ] diff --git a/eslint.config.mjs b/eslint.config.mjs index fe2dab72..326b24c2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -38,9 +38,25 @@ export default [ 'no-control-regex': 'off', 'no-fallthrough': ['error', { commentPattern: 'fallthrough' }], 'no-implicit-globals': 'error', + 'no-restricted-imports': [ + 'error', + { + patterns: [ + { + regex: '^\\..*(? diff --git a/src/compose/resolve-flow-scalar.ts b/src/compose/resolve-flow-scalar.ts index 0568dd9a..5568d63c 100644 --- a/src/compose/resolve-flow-scalar.ts +++ b/src/compose/resolve-flow-scalar.ts @@ -1,9 +1,9 @@ -import { ErrorCode } from '../errors.js' -import { Range } from '../nodes/Node.js' -import { Scalar } from '../nodes/Scalar.js' -import type { FlowScalar } from '../parse/cst.js' -import type { ComposeErrorHandler } from './composer.js' -import { resolveEnd } from './resolve-end.js' +import type { ErrorCode } from '../errors.ts' +import type { Range } from '../nodes/Node.ts' +import { Scalar } from '../nodes/Scalar.ts' +import type { FlowScalar } from '../parse/cst.ts' +import type { ComposeErrorHandler } from './composer.ts' +import { resolveEnd } from './resolve-end.ts' type FlowScalarErrorHandler = ( offset: number, diff --git a/src/compose/resolve-props.ts b/src/compose/resolve-props.ts index 20a1590e..1c16adb3 100644 --- a/src/compose/resolve-props.ts +++ b/src/compose/resolve-props.ts @@ -1,5 +1,5 @@ -import type { SourceToken, Token } from '../parse/cst.js' -import type { ComposeErrorHandler } from './composer.js' +import type { SourceToken, Token } from '../parse/cst.ts' +import type { ComposeErrorHandler } from './composer.ts' export interface ResolvePropsArg { flow?: 'flow map' | 'flow sequence' diff --git a/src/compose/util-contains-newline.ts b/src/compose/util-contains-newline.ts index a34e3066..41342077 100644 --- a/src/compose/util-contains-newline.ts +++ b/src/compose/util-contains-newline.ts @@ -1,4 +1,4 @@ -import type { Token } from '../parse/cst.js' +import type { Token } from '../parse/cst.ts' export function containsNewline(key: Token | null | undefined) { if (!key) return null diff --git a/src/compose/util-empty-scalar-position.ts b/src/compose/util-empty-scalar-position.ts index 51180717..48caf9db 100644 --- a/src/compose/util-empty-scalar-position.ts +++ b/src/compose/util-empty-scalar-position.ts @@ -1,4 +1,4 @@ -import type { Token } from '../parse/cst.js' +import type { Token } from '../parse/cst.ts' export function emptyScalarPosition( offset: number, diff --git a/src/compose/util-flow-indent-check.ts b/src/compose/util-flow-indent-check.ts index eb55719d..2f0e4076 100644 --- a/src/compose/util-flow-indent-check.ts +++ b/src/compose/util-flow-indent-check.ts @@ -1,6 +1,6 @@ -import { Token } from '../parse/cst' -import { ComposeErrorHandler } from './composer' -import { containsNewline } from './util-contains-newline' +import type { Token } from '../parse/cst.ts' +import type { ComposeErrorHandler } from './composer.ts' +import { containsNewline } from './util-contains-newline.ts' export function flowIndentCheck( indent: number, diff --git a/src/compose/util-map-includes.ts b/src/compose/util-map-includes.ts index ce20c118..1b5f8ed7 100644 --- a/src/compose/util-map-includes.ts +++ b/src/compose/util-map-includes.ts @@ -1,7 +1,7 @@ -import { isScalar } from '../nodes/identity.js' -import type { ParsedNode } from '../nodes/Node.js' -import type { Pair } from '../nodes/Pair.js' -import type { ComposeContext } from './compose-node.js' +import { isScalar } from '../nodes/identity.ts' +import type { ParsedNode } from '../nodes/Node.ts' +import type { Pair } from '../nodes/Pair.ts' +import type { ComposeContext } from './compose-node.ts' export function mapIncludes( ctx: ComposeContext, diff --git a/src/doc/Document.ts b/src/doc/Document.ts index 0eb38cfe..14456486 100644 --- a/src/doc/Document.ts +++ b/src/doc/Document.ts @@ -1,19 +1,20 @@ -import type { YAMLError, YAMLWarning } from '../errors.js' -import { Alias } from '../nodes/Alias.js' -import { collectionFromPath, isEmptyPath } from '../nodes/Collection.js' +import type { YAMLError, YAMLWarning } from '../errors.ts' +import { Alias } from '../nodes/Alias.ts' +import { collectionFromPath, isEmptyPath } from '../nodes/Collection.ts' import { DOC, isCollection, isNode, isScalar, NODE_TYPE -} from '../nodes/identity.js' -import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js' -import { Pair } from '../nodes/Pair.js' -import type { Scalar } from '../nodes/Scalar.js' -import { toJS, ToJSContext } from '../nodes/toJS.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { YAMLSeq } from '../nodes/YAMLSeq.js' +} from '../nodes/identity.ts' +import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.ts' +import { Pair } from '../nodes/Pair.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { ToJSContext } from '../nodes/toJS.ts' +import { toJS } from '../nodes/toJS.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { YAMLSeq } from '../nodes/YAMLSeq.ts' import type { CreateNodeOptions, DocumentOptions, @@ -21,13 +22,14 @@ import type { SchemaOptions, ToJSOptions, ToStringOptions -} from '../options.js' -import { Schema } from '../schema/Schema.js' -import { stringifyDocument } from '../stringify/stringifyDocument.js' -import { anchorNames, createNodeAnchors, findNewAnchor } from './anchors.js' -import { applyReviver } from './applyReviver.js' -import { createNode, CreateNodeContext } from './createNode.js' -import { Directives } from './directives.js' +} from '../options.ts' +import { Schema } from '../schema/Schema.ts' +import { stringifyDocument } from '../stringify/stringifyDocument.ts' +import { anchorNames, createNodeAnchors, findNewAnchor } from './anchors.ts' +import { applyReviver } from './applyReviver.ts' +import type { CreateNodeContext } from './createNode.ts' +import { createNode } from './createNode.ts' +import { Directives } from './directives.ts' export type Replacer = any[] | ((key: any, value: any) => unknown) diff --git a/src/doc/anchors.ts b/src/doc/anchors.ts index 7899fbe5..8379494a 100644 --- a/src/doc/anchors.ts +++ b/src/doc/anchors.ts @@ -1,11 +1,11 @@ -import { isCollection, isScalar } from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { YAMLSeq } from '../nodes/YAMLSeq.js' -import { visit } from '../visit.js' -import { CreateNodeContext } from './createNode.js' -import type { Document } from './Document.js' +import { isCollection, isScalar } from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { YAMLSeq } from '../nodes/YAMLSeq.ts' +import { visit } from '../visit.ts' +import type { CreateNodeContext } from './createNode.ts' +import type { Document } from './Document.ts' /** * Verify that the input string is a valid anchor. diff --git a/src/doc/createNode.ts b/src/doc/createNode.ts index c80805d2..203b5981 100644 --- a/src/doc/createNode.ts +++ b/src/doc/createNode.ts @@ -1,11 +1,11 @@ -import { Alias } from '../nodes/Alias.js' -import { isDocument, isNode, isPair, MAP, SEQ } from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import { Scalar } from '../nodes/Scalar.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { Schema } from '../schema/Schema.js' -import type { CollectionTag, ScalarTag } from '../schema/types.js' -import type { Replacer } from './Document.js' +import { Alias } from '../nodes/Alias.ts' +import { isDocument, isNode, isPair, MAP, SEQ } from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import { Scalar } from '../nodes/Scalar.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { Schema } from '../schema/Schema.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' +import type { Replacer } from './Document.ts' const defaultTagPrefix = 'tag:yaml.org,2002:' diff --git a/src/doc/directives.ts b/src/doc/directives.ts index 1b152996..37f1ce0b 100644 --- a/src/doc/directives.ts +++ b/src/doc/directives.ts @@ -1,6 +1,6 @@ -import { isNode } from '../nodes/identity.js' -import { visit } from '../visit.js' -import type { Document } from './Document.js' +import { isNode } from '../nodes/identity.ts' +import { visit } from '../visit.ts' +import type { Document } from './Document.ts' const escapeChars: Record = { '!': '%21', diff --git a/src/errors.ts b/src/errors.ts index a5b62b0c..1200d1d1 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,4 +1,4 @@ -import type { LineCounter } from './parse/line-counter' +import type { LineCounter } from './parse/line-counter.ts' export type ErrorCode = | 'ALIAS_PROPS' diff --git a/src/index.ts b/src/index.ts index 1b5ea23d..7cb9b7f2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,12 @@ -export { Composer } from './compose/composer.js' +export { Composer } from './compose/composer.ts' -export { Document } from './doc/Document.js' -export { Schema } from './schema/Schema.js' +export { Document } from './doc/Document.ts' +export { Schema } from './schema/Schema.ts' -export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js' +export type { ErrorCode } from './errors.ts' +export { YAMLError, YAMLParseError, YAMLWarning } from './errors.ts' -export { Alias } from './nodes/Alias.js' +export { Alias } from './nodes/Alias.ts' export { isAlias, isCollection, @@ -15,12 +16,12 @@ export { isPair, isScalar, isSeq -} from './nodes/identity.js' -export { Node, ParsedNode, Range } from './nodes/Node.js' -export { Pair } from './nodes/Pair.js' -export { Scalar } from './nodes/Scalar.js' -export { YAMLMap } from './nodes/YAMLMap.js' -export { YAMLSeq } from './nodes/YAMLSeq.js' +} from './nodes/identity.ts' +export type { Node, ParsedNode, Range } from './nodes/Node.ts' +export { Pair } from './nodes/Pair.ts' +export { Scalar } from './nodes/Scalar.ts' +export { YAMLMap } from './nodes/YAMLMap.ts' +export { YAMLSeq } from './nodes/YAMLSeq.ts' export type { CreateNodeOptions, @@ -29,31 +30,30 @@ export type { SchemaOptions, ToJSOptions, ToStringOptions -} from './options.js' +} from './options.ts' -export * as CST from './parse/cst.js' -export { Lexer } from './parse/lexer.js' -export { LineCounter } from './parse/line-counter.js' -export { Parser } from './parse/parser.js' +export * as CST from './parse/cst.ts' +export { Lexer } from './parse/lexer.ts' +export { LineCounter } from './parse/line-counter.ts' +export { Parser } from './parse/parser.ts' +export type { EmptyStream } from './public-api.ts' export { - EmptyStream, parse, parseAllDocuments, parseDocument, stringify -} from './public-api.js' +} from './public-api.ts' -export type { TagId, Tags } from './schema/tags' -export type { CollectionTag, ScalarTag } from './schema/types' -export type { YAMLOMap } from './schema/yaml-1.1/omap' -export type { YAMLSet } from './schema/yaml-1.1/set' +export type { TagId, Tags } from './schema/tags.ts' +export type { CollectionTag, ScalarTag } from './schema/types.ts' +export type { YAMLOMap } from './schema/yaml-1.1/omap.ts' +export type { YAMLSet } from './schema/yaml-1.1/set.ts' -export { +export type { asyncVisitor, asyncVisitorFn, - visit, - visitAsync, visitor, visitorFn -} from './visit.js' +} from './visit.ts' +export { visit, visitAsync } from './visit.ts' diff --git a/src/nodes/Alias.ts b/src/nodes/Alias.ts index b4bb5b3f..8461c3df 100644 --- a/src/nodes/Alias.ts +++ b/src/nodes/Alias.ts @@ -1,14 +1,16 @@ -import { anchorIsValid } from '../doc/anchors.js' -import type { Document } from '../doc/Document.js' -import type { FlowScalar } from '../parse/cst.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { visit } from '../visit.js' -import { ALIAS, isAlias, isCollection, isPair } from './identity.js' -import { Node, NodeBase, Range } from './Node.js' -import type { Scalar } from './Scalar' -import { toJS, ToJSContext } from './toJS.js' -import type { YAMLMap } from './YAMLMap.js' -import type { YAMLSeq } from './YAMLSeq.js' +import { anchorIsValid } from '../doc/anchors.ts' +import type { Document } from '../doc/Document.ts' +import type { FlowScalar } from '../parse/cst.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import { visit } from '../visit.ts' +import { ALIAS, isAlias, isCollection, isPair } from './identity.ts' +import type { Node, Range } from './Node.ts' +import { NodeBase } from './Node.ts' +import type { Scalar } from './Scalar.ts' +import type { ToJSContext } from './toJS.ts' +import { toJS } from './toJS.ts' +import type { YAMLMap } from './YAMLMap.ts' +import type { YAMLSeq } from './YAMLSeq.ts' export declare namespace Alias { interface Parsed extends Alias { diff --git a/src/nodes/Collection.ts b/src/nodes/Collection.ts index bb40d089..9e336b91 100644 --- a/src/nodes/Collection.ts +++ b/src/nodes/Collection.ts @@ -1,13 +1,13 @@ -import { createNode } from '../doc/createNode.js' -import type { Schema } from '../schema/Schema.js' +import { createNode } from '../doc/createNode.ts' +import type { Schema } from '../schema/Schema.ts' import { isCollection, isNode, isPair, isScalar, NODE_TYPE -} from './identity.js' -import { NodeBase } from './Node.js' +} from './identity.ts' +import { NodeBase } from './Node.ts' export function collectionFromPath( schema: Schema, diff --git a/src/nodes/Node.ts b/src/nodes/Node.ts index 49efb66a..0ecfbe8a 100644 --- a/src/nodes/Node.ts +++ b/src/nodes/Node.ts @@ -1,14 +1,15 @@ -import { applyReviver } from '../doc/applyReviver.js' -import type { Document } from '../doc/Document.js' -import type { ToJSOptions } from '../options.js' -import { Token } from '../parse/cst.js' -import type { StringifyContext } from '../stringify/stringify.js' -import type { Alias } from './Alias.js' -import { isDocument, NODE_TYPE } from './identity.js' -import type { Scalar } from './Scalar.js' -import { toJS, ToJSContext } from './toJS.js' -import type { MapLike, YAMLMap } from './YAMLMap.js' -import type { YAMLSeq } from './YAMLSeq.js' +import { applyReviver } from '../doc/applyReviver.ts' +import type { Document } from '../doc/Document.ts' +import type { ToJSOptions } from '../options.ts' +import type { Token } from '../parse/cst.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import type { Alias } from './Alias.ts' +import { isDocument, NODE_TYPE } from './identity.ts' +import type { Scalar } from './Scalar.ts' +import type { ToJSContext } from './toJS.ts' +import { toJS } from './toJS.ts' +import type { MapLike, YAMLMap } from './YAMLMap.ts' +import type { YAMLSeq } from './YAMLSeq.ts' export type Node = | Alias diff --git a/src/nodes/Pair.ts b/src/nodes/Pair.ts index 370fc2c3..e3f369f2 100644 --- a/src/nodes/Pair.ts +++ b/src/nodes/Pair.ts @@ -1,11 +1,12 @@ -import { createNode, CreateNodeContext } from '../doc/createNode.js' -import type { CollectionItem } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyPair } from '../stringify/stringifyPair.js' -import { addPairToJSMap } from './addPairToJSMap.js' -import { isNode, NODE_TYPE, PAIR } from './identity.js' -import type { ToJSContext } from './toJS.js' +import type { CreateNodeContext } from '../doc/createNode.ts' +import { createNode } from '../doc/createNode.ts' +import type { CollectionItem } from '../parse/cst.ts' +import type { Schema } from '../schema/Schema.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import { stringifyPair } from '../stringify/stringifyPair.ts' +import { addPairToJSMap } from './addPairToJSMap.ts' +import { isNode, NODE_TYPE, PAIR } from './identity.ts' +import type { ToJSContext } from './toJS.ts' export function createPair( key: unknown, diff --git a/src/nodes/Scalar.ts b/src/nodes/Scalar.ts index 59ea16a9..b9d92cd6 100644 --- a/src/nodes/Scalar.ts +++ b/src/nodes/Scalar.ts @@ -1,7 +1,9 @@ -import type { BlockScalar, FlowScalar } from '../parse/cst.js' -import { SCALAR } from './identity.js' -import { NodeBase, Range } from './Node.js' -import { toJS, ToJSContext } from './toJS.js' +import type { BlockScalar, FlowScalar } from '../parse/cst.ts' +import { SCALAR } from './identity.ts' +import type { Range } from './Node.ts' +import { NodeBase } from './Node.ts' +import type { ToJSContext } from './toJS.ts' +import { toJS } from './toJS.ts' export const isScalarValue = (value: unknown) => !value || (typeof value !== 'function' && typeof value !== 'object') diff --git a/src/nodes/YAMLMap.ts b/src/nodes/YAMLMap.ts index 74852304..23df326f 100644 --- a/src/nodes/YAMLMap.ts +++ b/src/nodes/YAMLMap.ts @@ -1,15 +1,16 @@ -import type { BlockMap, FlowCollection } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyCollection } from '../stringify/stringifyCollection.js' -import { CreateNodeContext } from '../util.js' -import { addPairToJSMap } from './addPairToJSMap.js' -import { Collection } from './Collection.js' -import { isPair, isScalar, MAP } from './identity.js' -import type { ParsedNode, Range } from './Node.js' -import { createPair, Pair } from './Pair.js' -import { isScalarValue, Scalar } from './Scalar.js' -import type { ToJSContext } from './toJS.js' +import type { BlockMap, FlowCollection } from '../parse/cst.ts' +import type { Schema } from '../schema/Schema.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import { stringifyCollection } from '../stringify/stringifyCollection.ts' +import type { CreateNodeContext } from '../util.ts' +import { addPairToJSMap } from './addPairToJSMap.ts' +import { Collection } from './Collection.ts' +import { isPair, isScalar, MAP } from './identity.ts' +import type { ParsedNode, Range } from './Node.ts' +import { createPair, Pair } from './Pair.ts' +import type { Scalar } from './Scalar.ts' +import { isScalarValue } from './Scalar.ts' +import type { ToJSContext } from './toJS.ts' export type MapLike = | Map diff --git a/src/nodes/YAMLSeq.ts b/src/nodes/YAMLSeq.ts index ada8c488..39e78dfb 100644 --- a/src/nodes/YAMLSeq.ts +++ b/src/nodes/YAMLSeq.ts @@ -1,14 +1,17 @@ -import { createNode, CreateNodeContext } from '../doc/createNode.js' -import type { BlockSequence, FlowCollection } from '../parse/cst.js' -import type { Schema } from '../schema/Schema.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyCollection } from '../stringify/stringifyCollection.js' -import { Collection } from './Collection.js' -import { isScalar, SEQ } from './identity.js' -import type { ParsedNode, Range } from './Node.js' -import type { Pair } from './Pair.js' -import { isScalarValue, Scalar } from './Scalar.js' -import { toJS, ToJSContext } from './toJS.js' +import type { CreateNodeContext } from '../doc/createNode.ts' +import { createNode } from '../doc/createNode.ts' +import type { BlockSequence, FlowCollection } from '../parse/cst.ts' +import type { Schema } from '../schema/Schema.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import { stringifyCollection } from '../stringify/stringifyCollection.ts' +import { Collection } from './Collection.ts' +import { isScalar, SEQ } from './identity.ts' +import type { ParsedNode, Range } from './Node.ts' +import type { Pair } from './Pair.ts' +import type { Scalar } from './Scalar.ts' +import { isScalarValue } from './Scalar.ts' +import type { ToJSContext } from './toJS.ts' +import { toJS } from './toJS.ts' export declare namespace YAMLSeq { interface Parsed< diff --git a/src/nodes/addPairToJSMap.ts b/src/nodes/addPairToJSMap.ts index 4ee9a395..08bb0608 100644 --- a/src/nodes/addPairToJSMap.ts +++ b/src/nodes/addPairToJSMap.ts @@ -1,10 +1,11 @@ -import { warn } from '../log.js' -import { addMergeToJSMap, isMergeKey } from '../schema/yaml-1.1/merge.js' -import { createStringifyContext } from '../stringify/stringify.js' -import { isNode } from './identity.js' -import type { Pair } from './Pair.js' -import { toJS, ToJSContext } from './toJS.js' -import type { MapLike } from './YAMLMap.js' +import { warn } from '../log.ts' +import { addMergeToJSMap, isMergeKey } from '../schema/yaml-1.1/merge.ts' +import { createStringifyContext } from '../stringify/stringify.ts' +import { isNode } from './identity.ts' +import type { Pair } from './Pair.ts' +import type { ToJSContext } from './toJS.ts' +import { toJS } from './toJS.ts' +import type { MapLike } from './YAMLMap.ts' export function addPairToJSMap( ctx: ToJSContext | undefined, diff --git a/src/nodes/identity.ts b/src/nodes/identity.ts index f7a6eb43..17fa55bb 100644 --- a/src/nodes/identity.ts +++ b/src/nodes/identity.ts @@ -1,10 +1,10 @@ -import type { Document } from '../doc/Document.js' -import type { Alias } from './Alias.js' -import type { Node } from './Node.js' -import type { Pair } from './Pair.js' -import type { Scalar } from './Scalar.js' -import type { YAMLMap } from './YAMLMap.js' -import type { YAMLSeq } from './YAMLSeq.js' +import type { Document } from '../doc/Document.ts' +import type { Alias } from './Alias.ts' +import type { Node } from './Node.ts' +import type { Pair } from './Pair.ts' +import type { Scalar } from './Scalar.ts' +import type { YAMLMap } from './YAMLMap.ts' +import type { YAMLSeq } from './YAMLSeq.ts' export const ALIAS = Symbol.for('yaml.alias') export const DOC = Symbol.for('yaml.document') diff --git a/src/nodes/toJS.ts b/src/nodes/toJS.ts index ac7d3944..5732668e 100644 --- a/src/nodes/toJS.ts +++ b/src/nodes/toJS.ts @@ -1,6 +1,6 @@ -import type { Document } from '../doc/Document.js' -import { hasAnchor } from './identity.js' -import type { Node } from './Node.js' +import type { Document } from '../doc/Document.ts' +import { hasAnchor } from './identity.ts' +import type { Node } from './Node.ts' export interface AnchorData { aliasCount: number diff --git a/src/options.ts b/src/options.ts index b586e206..2b8a0585 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,13 +1,13 @@ -import type { Reviver } from './doc/applyReviver.js' -import type { Directives } from './doc/directives.js' -import type { LogLevelId } from './log.js' -import type { ParsedNode } from './nodes/Node.js' -import type { Pair } from './nodes/Pair.js' -import type { Scalar } from './nodes/Scalar.js' -import type { LineCounter } from './parse/line-counter.js' -import type { Schema } from './schema/Schema.js' -import type { Tags } from './schema/tags.js' -import type { CollectionTag, ScalarTag } from './schema/types.js' +import type { Reviver } from './doc/applyReviver.ts' +import type { Directives } from './doc/directives.ts' +import type { LogLevelId } from './log.ts' +import type { ParsedNode } from './nodes/Node.ts' +import type { Pair } from './nodes/Pair.ts' +import type { Scalar } from './nodes/Scalar.ts' +import type { LineCounter } from './parse/line-counter.ts' +import type { Schema } from './schema/Schema.ts' +import type { Tags } from './schema/tags.ts' +import type { CollectionTag, ScalarTag } from './schema/types.ts' export type ParseOptions = { /** diff --git a/src/parse/cst-scalar.ts b/src/parse/cst-scalar.ts index c70c3755..e10d3a6d 100644 --- a/src/parse/cst-scalar.ts +++ b/src/parse/cst-scalar.ts @@ -1,13 +1,14 @@ -import type { ComposeContext } from '../compose/compose-node.js' -import type { ComposeErrorHandler } from '../compose/composer.js' -import { resolveBlockScalar } from '../compose/resolve-block-scalar.js' -import { resolveFlowScalar } from '../compose/resolve-flow-scalar.js' -import { ErrorCode, YAMLParseError } from '../errors.js' -import { Range } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { StringifyContext } from '../stringify/stringify.js' -import { stringifyString } from '../stringify/stringifyString.js' -import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js' +import type { ComposeContext } from '../compose/compose-node.ts' +import type { ComposeErrorHandler } from '../compose/composer.ts' +import { resolveBlockScalar } from '../compose/resolve-block-scalar.ts' +import { resolveFlowScalar } from '../compose/resolve-flow-scalar.ts' +import type { ErrorCode } from '../errors.ts' +import { YAMLParseError } from '../errors.ts' +import type { Range } from '../nodes/Node.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import { stringifyString } from '../stringify/stringifyString.ts' +import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.ts' /** * If `token` is a CST flow or block scalar, determine its string value and a few other attributes. diff --git a/src/parse/cst-stringify.ts b/src/parse/cst-stringify.ts index 511c082c..e428c2c7 100644 --- a/src/parse/cst-stringify.ts +++ b/src/parse/cst-stringify.ts @@ -1,4 +1,4 @@ -import type { CollectionItem, Token } from './cst.js' +import type { CollectionItem, Token } from './cst.ts' /** * Stringify a CST document, token, or collection item diff --git a/src/parse/cst-visit.ts b/src/parse/cst-visit.ts index f3a48ce6..01b9aa9d 100644 --- a/src/parse/cst-visit.ts +++ b/src/parse/cst-visit.ts @@ -1,4 +1,4 @@ -import type { CollectionItem, Document } from './cst.js' +import type { CollectionItem, Document } from './cst.ts' const BREAK = Symbol('break visit') const SKIP = Symbol('skip children') diff --git a/src/parse/cst.ts b/src/parse/cst.ts index 82b66dee..c73cdcc3 100644 --- a/src/parse/cst.ts +++ b/src/parse/cst.ts @@ -2,9 +2,10 @@ export { createScalarToken, resolveAsScalar, setScalarValue -} from './cst-scalar.js' -export { stringify } from './cst-stringify.js' -export { visit, Visitor, VisitPath } from './cst-visit.js' +} from './cst-scalar.ts' +export { stringify } from './cst-stringify.ts' +export type { Visitor, VisitPath } from './cst-visit.ts' +export { visit } from './cst-visit.ts' export interface SourceToken { type: diff --git a/src/parse/lexer.ts b/src/parse/lexer.ts index af06ee54..ebe7f137 100644 --- a/src/parse/lexer.ts +++ b/src/parse/lexer.ts @@ -66,7 +66,7 @@ plain-scalar(is-flow, min) [else] -> plain-scalar(min) */ -import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js' +import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.ts' type State = | 'stream' diff --git a/src/parse/parser.ts b/src/parse/parser.ts index 6385186a..3859d655 100644 --- a/src/parse/parser.ts +++ b/src/parse/parser.ts @@ -1,4 +1,4 @@ -import { +import type { SourceToken, Token, FlowScalar, @@ -8,11 +8,10 @@ import { BlockScalar, BlockSequence, DocumentEnd, - prettyToken, - tokenType, TokenType -} from './cst.js' -import { Lexer } from './lexer.js' +} from './cst.ts' +import { prettyToken, tokenType } from './cst.ts' +import { Lexer } from './lexer.ts' function includesToken(list: SourceToken[], type: SourceToken['type']) { for (let i = 0; i < list.length; ++i) if (list[i].type === type) return true diff --git a/src/public-api.ts b/src/public-api.ts index a5e05327..407fb496 100644 --- a/src/public-api.ts +++ b/src/public-api.ts @@ -1,10 +1,11 @@ -import { Composer } from './compose/composer.js' -import type { Reviver } from './doc/applyReviver.js' -import { Document, Replacer } from './doc/Document.js' -import { prettifyError, YAMLParseError } from './errors.js' -import { warn } from './log.js' -import { isDocument } from './nodes/identity.js' -import type { Node, ParsedNode } from './nodes/Node.js' +import { Composer } from './compose/composer.ts' +import type { Reviver } from './doc/applyReviver.ts' +import type { Replacer } from './doc/Document.ts' +import { Document } from './doc/Document.ts' +import { prettifyError, YAMLParseError } from './errors.ts' +import { warn } from './log.ts' +import { isDocument } from './nodes/identity.ts' +import type { Node, ParsedNode } from './nodes/Node.ts' import type { CreateNodeOptions, DocumentOptions, @@ -12,9 +13,9 @@ import type { SchemaOptions, ToJSOptions, ToStringOptions -} from './options.js' -import { LineCounter } from './parse/line-counter.js' -import { Parser } from './parse/parser.js' +} from './options.ts' +import { LineCounter } from './parse/line-counter.ts' +import { Parser } from './parse/parser.ts' export interface EmptyStream extends Array, diff --git a/src/schema/Schema.ts b/src/schema/Schema.ts index 209e23bd..de6a1acf 100644 --- a/src/schema/Schema.ts +++ b/src/schema/Schema.ts @@ -1,11 +1,11 @@ -import { MAP, SCALAR, SEQ } from '../nodes/identity.js' -import type { Pair } from '../nodes/Pair.js' -import type { SchemaOptions, ToStringOptions } from '../options.js' -import { map } from './common/map.js' -import { seq } from './common/seq.js' -import { string } from './common/string.js' -import { coreKnownTags, getTags } from './tags.js' -import type { CollectionTag, ScalarTag } from './types.js' +import { MAP, SCALAR, SEQ } from '../nodes/identity.ts' +import type { Pair } from '../nodes/Pair.ts' +import type { SchemaOptions, ToStringOptions } from '../options.ts' +import { map } from './common/map.ts' +import { seq } from './common/seq.ts' +import { string } from './common/string.ts' +import { coreKnownTags, getTags } from './tags.ts' +import type { CollectionTag, ScalarTag } from './types.ts' const sortMapEntriesByKey = (a: Pair, b: Pair) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0 diff --git a/src/schema/common/map.ts b/src/schema/common/map.ts index 8583d553..3f9a22e0 100644 --- a/src/schema/common/map.ts +++ b/src/schema/common/map.ts @@ -1,6 +1,6 @@ -import { isMap } from '../../nodes/identity.js' -import { YAMLMap } from '../../nodes/YAMLMap.js' -import type { CollectionTag } from '../types.js' +import { isMap } from '../../nodes/identity.ts' +import { YAMLMap } from '../../nodes/YAMLMap.ts' +import type { CollectionTag } from '../types.ts' export const map: CollectionTag = { collection: 'map', diff --git a/src/schema/common/null.ts b/src/schema/common/null.ts index b8ad7dfd..082d52ee 100644 --- a/src/schema/common/null.ts +++ b/src/schema/common/null.ts @@ -1,5 +1,5 @@ -import { Scalar } from '../../nodes/Scalar.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import type { ScalarTag } from '../types.ts' export const nullTag: ScalarTag & { test: RegExp } = { identify: value => value == null, diff --git a/src/schema/common/seq.ts b/src/schema/common/seq.ts index 8bdcab74..401e9c74 100644 --- a/src/schema/common/seq.ts +++ b/src/schema/common/seq.ts @@ -1,6 +1,6 @@ -import { isSeq } from '../../nodes/identity.js' -import { YAMLSeq } from '../../nodes/YAMLSeq.js' -import type { CollectionTag } from '../types.js' +import { isSeq } from '../../nodes/identity.ts' +import { YAMLSeq } from '../../nodes/YAMLSeq.ts' +import type { CollectionTag } from '../types.ts' export const seq: CollectionTag = { collection: 'seq', diff --git a/src/schema/common/string.ts b/src/schema/common/string.ts index 2d4a091e..6ae0b4ec 100644 --- a/src/schema/common/string.ts +++ b/src/schema/common/string.ts @@ -1,5 +1,5 @@ -import { stringifyString } from '../../stringify/stringifyString.js' -import type { ScalarTag } from '../types.js' +import { stringifyString } from '../../stringify/stringifyString.ts' +import type { ScalarTag } from '../types.ts' export const string: ScalarTag = { identify: value => typeof value === 'string', diff --git a/src/schema/core/bool.ts b/src/schema/core/bool.ts index 26daef6f..279dd925 100644 --- a/src/schema/core/bool.ts +++ b/src/schema/core/bool.ts @@ -1,5 +1,5 @@ -import { Scalar } from '../../nodes/Scalar.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import type { ScalarTag } from '../types.ts' export const boolTag: ScalarTag & { test: RegExp } = { identify: value => typeof value === 'boolean', diff --git a/src/schema/core/float.ts b/src/schema/core/float.ts index fad731a9..56146a48 100644 --- a/src/schema/core/float.ts +++ b/src/schema/core/float.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' export const floatNaN: ScalarTag = { identify: value => typeof value === 'number', diff --git a/src/schema/core/int.ts b/src/schema/core/int.ts index 8f5f16d1..a5bcd2ce 100644 --- a/src/schema/core/int.ts +++ b/src/schema/core/int.ts @@ -1,7 +1,7 @@ -import type { Scalar } from '../../nodes/Scalar.js' -import type { ParseOptions } from '../../options.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import type { Scalar } from '../../nodes/Scalar.ts' +import type { ParseOptions } from '../../options.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' const intIdentify = (value: unknown): value is number | bigint => typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/core/schema.ts b/src/schema/core/schema.ts index 37d64cd9..98698ded 100644 --- a/src/schema/core/schema.ts +++ b/src/schema/core/schema.ts @@ -1,10 +1,10 @@ -import { map } from '../common/map.js' -import { nullTag } from '../common/null.js' -import { seq } from '../common/seq.js' -import { string } from '../common/string.js' -import { boolTag } from './bool.js' -import { float, floatExp, floatNaN } from './float.js' -import { int, intHex, intOct } from './int.js' +import { map } from '../common/map.ts' +import { nullTag } from '../common/null.ts' +import { seq } from '../common/seq.ts' +import { string } from '../common/string.ts' +import { boolTag } from './bool.ts' +import { float, floatExp, floatNaN } from './float.ts' +import { int, intHex, intOct } from './int.ts' export const schema = [ map, diff --git a/src/schema/json/schema.ts b/src/schema/json/schema.ts index d8424012..fb72cdc0 100644 --- a/src/schema/json/schema.ts +++ b/src/schema/json/schema.ts @@ -1,7 +1,7 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { map } from '../common/map.js' -import { seq } from '../common/seq.js' -import { CollectionTag, ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { map } from '../common/map.ts' +import { seq } from '../common/seq.ts' +import type { CollectionTag, ScalarTag } from '../types.ts' function intIdentify(value: unknown): value is number | bigint { return typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/tags.ts b/src/schema/tags.ts index 483f9169..15e50ebf 100644 --- a/src/schema/tags.ts +++ b/src/schema/tags.ts @@ -1,21 +1,21 @@ -import { SchemaOptions } from '../options.js' -import { map } from './common/map.js' -import { nullTag } from './common/null.js' -import { seq } from './common/seq.js' -import { string } from './common/string.js' -import { boolTag } from './core/bool.js' -import { float, floatExp, floatNaN } from './core/float.js' -import { int, intHex, intOct } from './core/int.js' -import { schema as core } from './core/schema.js' -import { schema as json } from './json/schema.js' -import { binary } from './yaml-1.1/binary.js' -import { merge } from './yaml-1.1/merge.js' -import { omap } from './yaml-1.1/omap.js' -import { pairs } from './yaml-1.1/pairs.js' -import { schema as yaml11 } from './yaml-1.1/schema.js' -import { set } from './yaml-1.1/set.js' -import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.js' -import type { CollectionTag, ScalarTag } from './types.js' +import type { SchemaOptions } from '../options.ts' +import { map } from './common/map.ts' +import { nullTag } from './common/null.ts' +import { seq } from './common/seq.ts' +import { string } from './common/string.ts' +import { boolTag } from './core/bool.ts' +import { float, floatExp, floatNaN } from './core/float.ts' +import { int, intHex, intOct } from './core/int.ts' +import { schema as core } from './core/schema.ts' +import { schema as json } from './json/schema.ts' +import type { CollectionTag, ScalarTag } from './types.ts' +import { binary } from './yaml-1.1/binary.ts' +import { merge } from './yaml-1.1/merge.ts' +import { omap } from './yaml-1.1/omap.ts' +import { pairs } from './yaml-1.1/pairs.ts' +import { schema as yaml11 } from './yaml-1.1/schema.ts' +import { set } from './yaml-1.1/set.ts' +import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.ts' const schemas = new Map>([ ['core', core], diff --git a/src/schema/types.ts b/src/schema/types.ts index 0a400176..0583ffc3 100644 --- a/src/schema/types.ts +++ b/src/schema/types.ts @@ -1,11 +1,11 @@ -import type { CreateNodeContext } from '../doc/createNode.js' -import type { Node } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { YAMLMap } from '../nodes/YAMLMap.js' -import type { YAMLSeq } from '../nodes/YAMLSeq.js' -import type { ParseOptions } from '../options.js' -import type { StringifyContext } from '../stringify/stringify.js' -import type { Schema } from './Schema.js' +import type { CreateNodeContext } from '../doc/createNode.ts' +import type { Node } from '../nodes/Node.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { YAMLMap } from '../nodes/YAMLMap.ts' +import type { YAMLSeq } from '../nodes/YAMLSeq.ts' +import type { ParseOptions } from '../options.ts' +import type { StringifyContext } from '../stringify/stringify.ts' +import type { Schema } from './Schema.ts' interface TagBase { /** diff --git a/src/schema/yaml-1.1/binary.ts b/src/schema/yaml-1.1/binary.ts index 1d40ddfc..5ed97cc2 100644 --- a/src/schema/yaml-1.1/binary.ts +++ b/src/schema/yaml-1.1/binary.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { stringifyString } from '../../stringify/stringifyString.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { stringifyString } from '../../stringify/stringifyString.ts' +import type { ScalarTag } from '../types.ts' export const binary: ScalarTag = { identify: value => value instanceof Uint8Array, // Buffer inherits from Uint8Array diff --git a/src/schema/yaml-1.1/bool.ts b/src/schema/yaml-1.1/bool.ts index 10d68d40..c7e2bb7f 100644 --- a/src/schema/yaml-1.1/bool.ts +++ b/src/schema/yaml-1.1/bool.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import type { StringifyContext } from '../../stringify/stringify.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import type { StringifyContext } from '../../stringify/stringify.ts' +import type { ScalarTag } from '../types.ts' function boolStringify({ value, source }: Scalar, ctx: StringifyContext) { const boolObj = value ? trueTag : falseTag diff --git a/src/schema/yaml-1.1/float.ts b/src/schema/yaml-1.1/float.ts index 87e52b63..88ea3baf 100644 --- a/src/schema/yaml-1.1/float.ts +++ b/src/schema/yaml-1.1/float.ts @@ -1,6 +1,6 @@ -import { Scalar } from '../../nodes/Scalar.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import { Scalar } from '../../nodes/Scalar.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' export const floatNaN: ScalarTag = { identify: value => typeof value === 'number', diff --git a/src/schema/yaml-1.1/int.ts b/src/schema/yaml-1.1/int.ts index 2dac5134..68b6450a 100644 --- a/src/schema/yaml-1.1/int.ts +++ b/src/schema/yaml-1.1/int.ts @@ -1,7 +1,7 @@ -import type { Scalar } from '../../nodes/Scalar.js' -import type { ParseOptions } from '../../options.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import type { Scalar } from '../../nodes/Scalar.ts' +import type { ParseOptions } from '../../options.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' const intIdentify = (value: unknown): value is number | bigint => typeof value === 'bigint' || Number.isInteger(value) diff --git a/src/schema/yaml-1.1/merge.ts b/src/schema/yaml-1.1/merge.ts index 68d4bce5..64484b10 100644 --- a/src/schema/yaml-1.1/merge.ts +++ b/src/schema/yaml-1.1/merge.ts @@ -1,8 +1,8 @@ -import { isAlias, isMap, isScalar, isSeq } from '../../nodes/identity.js' -import { Scalar } from '../../nodes/Scalar.js' -import type { ToJSContext } from '../../nodes/toJS.js' -import type { MapLike } from '../../nodes/YAMLMap.js' -import type { ScalarTag } from '../types.js' +import { isAlias, isMap, isScalar, isSeq } from '../../nodes/identity.ts' +import { Scalar } from '../../nodes/Scalar.ts' +import type { ToJSContext } from '../../nodes/toJS.ts' +import type { MapLike } from '../../nodes/YAMLMap.ts' +import type { ScalarTag } from '../types.ts' // If the value associated with a merge key is a single mapping node, each of // its key/value pairs is inserted into the current mapping, unless the key diff --git a/src/schema/yaml-1.1/omap.ts b/src/schema/yaml-1.1/omap.ts index f08b8fd0..f3baa1a8 100644 --- a/src/schema/yaml-1.1/omap.ts +++ b/src/schema/yaml-1.1/omap.ts @@ -1,11 +1,12 @@ -import { isPair, isScalar } from '../../nodes/identity.js' -import { toJS, ToJSContext } from '../../nodes/toJS.js' -import { YAMLMap } from '../../nodes/YAMLMap.js' -import { YAMLSeq } from '../../nodes/YAMLSeq.js' -import { CreateNodeContext } from '../../util.js' -import type { Schema } from '../Schema.js' -import { CollectionTag } from '../types.js' -import { createPairs, resolvePairs } from './pairs.js' +import { isPair, isScalar } from '../../nodes/identity.ts' +import type { ToJSContext } from '../../nodes/toJS.ts' +import { toJS } from '../../nodes/toJS.ts' +import { YAMLMap } from '../../nodes/YAMLMap.ts' +import { YAMLSeq } from '../../nodes/YAMLSeq.ts' +import type { CreateNodeContext } from '../../util.ts' +import type { Schema } from '../Schema.ts' +import type { CollectionTag } from '../types.ts' +import { createPairs, resolvePairs } from './pairs.ts' export class YAMLOMap extends YAMLSeq { static tag = 'tag:yaml.org,2002:omap' diff --git a/src/schema/yaml-1.1/pairs.ts b/src/schema/yaml-1.1/pairs.ts index 248a847a..dcac4166 100644 --- a/src/schema/yaml-1.1/pairs.ts +++ b/src/schema/yaml-1.1/pairs.ts @@ -1,12 +1,12 @@ -import type { CreateNodeContext } from '../../doc/createNode.js' -import { isMap, isPair, isSeq } from '../../nodes/identity.js' -import type { ParsedNode } from '../../nodes/Node.js' -import { createPair, Pair } from '../../nodes/Pair.js' -import { Scalar } from '../../nodes/Scalar.js' -import { YAMLMap } from '../../nodes/YAMLMap.js' -import { YAMLSeq } from '../../nodes/YAMLSeq.js' -import type { Schema } from '../../schema/Schema.js' -import type { CollectionTag } from '../types.js' +import type { CreateNodeContext } from '../../doc/createNode.ts' +import { isMap, isPair, isSeq } from '../../nodes/identity.ts' +import type { ParsedNode } from '../../nodes/Node.ts' +import { createPair, Pair } from '../../nodes/Pair.ts' +import { Scalar } from '../../nodes/Scalar.ts' +import type { YAMLMap } from '../../nodes/YAMLMap.ts' +import { YAMLSeq } from '../../nodes/YAMLSeq.ts' +import type { Schema } from '../../schema/Schema.ts' +import type { CollectionTag } from '../types.ts' export function resolvePairs( seq: diff --git a/src/schema/yaml-1.1/schema.ts b/src/schema/yaml-1.1/schema.ts index c7b700b9..85591b3a 100644 --- a/src/schema/yaml-1.1/schema.ts +++ b/src/schema/yaml-1.1/schema.ts @@ -1,16 +1,16 @@ -import { map } from '../common/map.js' -import { nullTag } from '../common/null.js' -import { seq } from '../common/seq.js' -import { string } from '../common/string.js' -import { binary } from './binary.js' -import { falseTag, trueTag } from './bool.js' -import { float, floatExp, floatNaN } from './float.js' -import { intBin, int, intHex, intOct } from './int.js' -import { merge } from './merge.js' -import { omap } from './omap.js' -import { pairs } from './pairs.js' -import { set } from './set.js' -import { intTime, floatTime, timestamp } from './timestamp.js' +import { map } from '../common/map.ts' +import { nullTag } from '../common/null.ts' +import { seq } from '../common/seq.ts' +import { string } from '../common/string.ts' +import { binary } from './binary.ts' +import { falseTag, trueTag } from './bool.ts' +import { float, floatExp, floatNaN } from './float.ts' +import { intBin, int, intHex, intOct } from './int.ts' +import { merge } from './merge.ts' +import { omap } from './omap.ts' +import { pairs } from './pairs.ts' +import { set } from './set.ts' +import { intTime, floatTime, timestamp } from './timestamp.ts' export const schema = [ map, diff --git a/src/schema/yaml-1.1/set.ts b/src/schema/yaml-1.1/set.ts index 33275a99..b1396fde 100644 --- a/src/schema/yaml-1.1/set.ts +++ b/src/schema/yaml-1.1/set.ts @@ -1,12 +1,13 @@ -import { isMap, isPair, isScalar } from '../../nodes/identity.js' -import { Pair } from '../../nodes/Pair.js' -import { Scalar } from '../../nodes/Scalar.js' -import { ToJSContext } from '../../nodes/toJS.js' -import { findPair, YAMLMap } from '../../nodes/YAMLMap.js' -import type { Schema } from '../../schema/Schema.js' -import type { StringifyContext } from '../../stringify/stringify.js' -import { CreateNodeContext, createPair } from '../../util.js' -import type { CollectionTag } from '../types.js' +import { isMap, isPair, isScalar } from '../../nodes/identity.ts' +import { Pair } from '../../nodes/Pair.ts' +import type { Scalar } from '../../nodes/Scalar.ts' +import type { ToJSContext } from '../../nodes/toJS.ts' +import { findPair, YAMLMap } from '../../nodes/YAMLMap.ts' +import type { Schema } from '../../schema/Schema.ts' +import type { StringifyContext } from '../../stringify/stringify.ts' +import type { CreateNodeContext } from '../../util.ts' +import { createPair } from '../../util.ts' +import type { CollectionTag } from '../types.ts' export class YAMLSet extends YAMLMap | null> { static tag = 'tag:yaml.org,2002:set' diff --git a/src/schema/yaml-1.1/timestamp.ts b/src/schema/yaml-1.1/timestamp.ts index 2cdc79bc..b59d6c73 100644 --- a/src/schema/yaml-1.1/timestamp.ts +++ b/src/schema/yaml-1.1/timestamp.ts @@ -1,6 +1,6 @@ -import type { Scalar } from '../../nodes/Scalar.js' -import { stringifyNumber } from '../../stringify/stringifyNumber.js' -import type { ScalarTag } from '../types.js' +import type { Scalar } from '../../nodes/Scalar.ts' +import { stringifyNumber } from '../../stringify/stringifyNumber.ts' +import type { ScalarTag } from '../types.ts' /** Internal types handle bigint as number, because TS can't figure it out. */ function parseSexagesimal(str: string, asBigInt?: B) { diff --git a/src/stringify/stringify.ts b/src/stringify/stringify.ts index 0c454709..e699f4c1 100644 --- a/src/stringify/stringify.ts +++ b/src/stringify/stringify.ts @@ -1,19 +1,19 @@ -import { anchorIsValid } from '../doc/anchors.js' -import type { Document } from '../doc/Document.js' -import type { Alias } from '../nodes/Alias.js' +import { anchorIsValid } from '../doc/anchors.ts' +import type { Document } from '../doc/Document.ts' +import type { Alias } from '../nodes/Alias.ts' import { isAlias, isCollection, isNode, isPair, isScalar -} from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import type { Scalar } from '../nodes/Scalar.js' -import type { ToStringOptions } from '../options.js' -import type { CollectionTag, ScalarTag } from '../schema/types.js' -import { stringifyComment } from './stringifyComment.js' -import { stringifyString } from './stringifyString.js' +} from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import type { Scalar } from '../nodes/Scalar.ts' +import type { ToStringOptions } from '../options.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' +import { stringifyComment } from './stringifyComment.ts' +import { stringifyString } from './stringifyString.ts' export type StringifyContext = { actualString?: boolean diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index 5c4291c0..a920fe34 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -1,7 +1,8 @@ -import { Collection } from '../nodes/Collection.js' -import { isNode, isPair } from '../nodes/identity.js' -import { stringify, StringifyContext } from './stringify.js' -import { indentComment, lineComment } from './stringifyComment.js' +import type { Collection } from '../nodes/Collection.ts' +import { isNode, isPair } from '../nodes/identity.ts' +import type { StringifyContext } from './stringify.ts' +import { stringify } from './stringify.ts' +import { indentComment, lineComment } from './stringifyComment.ts' interface StringifyCollectionOptions { blockItemPrefix: string diff --git a/src/stringify/stringifyDocument.ts b/src/stringify/stringifyDocument.ts index ce7337b4..d3b91e06 100644 --- a/src/stringify/stringifyDocument.ts +++ b/src/stringify/stringifyDocument.ts @@ -1,13 +1,13 @@ -import type { Document } from '../doc/Document.js' -import { isNode } from '../nodes/identity.js' -import type { Node } from '../nodes/Node.js' -import type { ToStringOptions } from '../options.js' +import type { Document } from '../doc/Document.ts' +import { isNode } from '../nodes/identity.ts' +import type { Node } from '../nodes/Node.ts' +import type { ToStringOptions } from '../options.ts' import { createStringifyContext, stringify, - StringifyContext -} from './stringify.js' -import { indentComment, lineComment } from './stringifyComment.js' + type StringifyContext +} from './stringify.ts' +import { indentComment, lineComment } from './stringifyComment.ts' export function stringifyDocument( doc: Readonly>, diff --git a/src/stringify/stringifyNumber.ts b/src/stringify/stringifyNumber.ts index b12d8459..455bc750 100644 --- a/src/stringify/stringifyNumber.ts +++ b/src/stringify/stringifyNumber.ts @@ -1,4 +1,4 @@ -import type { Scalar } from '../nodes/Scalar.js' +import type { Scalar } from '../nodes/Scalar.ts' export function stringifyNumber({ format, diff --git a/src/stringify/stringifyPair.ts b/src/stringify/stringifyPair.ts index 4ef6710f..fddcb1b7 100644 --- a/src/stringify/stringifyPair.ts +++ b/src/stringify/stringifyPair.ts @@ -1,8 +1,9 @@ -import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js' -import type { Pair } from '../nodes/Pair.js' -import { Scalar } from '../nodes/Scalar.js' -import { stringify, StringifyContext } from './stringify.js' -import { indentComment, lineComment } from './stringifyComment.js' +import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.ts' +import type { Pair } from '../nodes/Pair.ts' +import { Scalar } from '../nodes/Scalar.ts' +import type { StringifyContext } from './stringify.ts' +import { stringify } from './stringify.ts' +import { indentComment, lineComment } from './stringifyComment.ts' export function stringifyPair( { key, value }: Readonly, diff --git a/src/stringify/stringifyString.ts b/src/stringify/stringifyString.ts index b21dedd2..2de6aa37 100644 --- a/src/stringify/stringifyString.ts +++ b/src/stringify/stringifyString.ts @@ -1,13 +1,13 @@ -import { Scalar } from '../nodes/Scalar.js' +import { Scalar } from '../nodes/Scalar.ts' +import type { CollectionTag, ScalarTag } from '../schema/types.ts' import { - foldFlowLines, - FoldOptions, FOLD_BLOCK, FOLD_FLOW, - FOLD_QUOTED -} from './foldFlowLines.js' -import type { CollectionTag, ScalarTag } from '../schema/types.js' -import type { StringifyContext } from './stringify.js' + FOLD_QUOTED, + foldFlowLines, + type FoldOptions +} from './foldFlowLines.ts' +import type { StringifyContext } from './stringify.ts' interface StringifyScalar { value: string diff --git a/src/test-events.ts b/src/test-events.ts index ca7c6c83..c0260152 100644 --- a/src/test-events.ts +++ b/src/test-events.ts @@ -1,4 +1,4 @@ -import { Document } from './doc/Document.js' +import type { Document } from './doc/Document.ts' import { isAlias, isCollection, @@ -7,11 +7,11 @@ import { isPair, isScalar, isSeq -} from './nodes/identity.js' -import type { Node, ParsedNode } from './nodes/Node.js' -import type { Pair } from './nodes/Pair.js' -import { parseAllDocuments } from './public-api.js' -import { visit } from './visit.js' +} from './nodes/identity.ts' +import type { Node, ParsedNode } from './nodes/Node.ts' +import type { Pair } from './nodes/Pair.ts' +import { parseAllDocuments } from './public-api.ts' +import { visit } from './visit.ts' const scalarChar: Record = { BLOCK_FOLDED: '>', diff --git a/src/util.ts b/src/util.ts index ba7b59f1..d1b9aa83 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,12 +1,16 @@ -export { createNode, CreateNodeContext } from './doc/createNode.js' -export { debug, LogLevelId, warn } from './log.js' -export { createPair } from './nodes/Pair.js' -export { findPair } from './nodes/YAMLMap.js' -export { toJS, ToJSContext } from './nodes/toJS.js' -export { map as mapTag } from './schema/common/map.js' -export { seq as seqTag } from './schema/common/seq.js' -export { string as stringTag } from './schema/common/string.js' -export { foldFlowLines, FoldOptions } from './stringify/foldFlowLines' -export { StringifyContext } from './stringify/stringify.js' -export { stringifyNumber } from './stringify/stringifyNumber.js' -export { stringifyString } from './stringify/stringifyString.js' +export { createNode } from './doc/createNode.ts' +export type { CreateNodeContext } from './doc/createNode.ts' +export { debug, warn } from './log.ts' +export type { LogLevelId } from './log.ts' +export { createPair } from './nodes/Pair.ts' +export { toJS } from './nodes/toJS.ts' +export type { ToJSContext } from './nodes/toJS.ts' +export { findPair } from './nodes/YAMLMap.ts' +export { map as mapTag } from './schema/common/map.ts' +export { seq as seqTag } from './schema/common/seq.ts' +export { string as stringTag } from './schema/common/string.ts' +export { foldFlowLines } from './stringify/foldFlowLines.ts' +export type { FoldOptions } from './stringify/foldFlowLines.ts' +export type { StringifyContext } from './stringify/stringify.ts' +export { stringifyNumber } from './stringify/stringifyNumber.ts' +export { stringifyString } from './stringify/stringifyString.ts' diff --git a/src/visit.ts b/src/visit.ts index e5291b36..0a1490f3 100644 --- a/src/visit.ts +++ b/src/visit.ts @@ -1,5 +1,5 @@ -import type { Document } from './doc/Document.js' -import type { Alias } from './nodes/Alias.js' +import type { Document } from './doc/Document.ts' +import type { Alias } from './nodes/Alias.ts' import { isAlias, isCollection, @@ -9,12 +9,12 @@ import { isPair, isScalar, isSeq -} from './nodes/identity.js' -import { Node } from './nodes/Node.js' -import type { Pair } from './nodes/Pair.js' -import type { Scalar } from './nodes/Scalar.js' -import type { YAMLMap } from './nodes/YAMLMap.js' -import type { YAMLSeq } from './nodes/YAMLSeq.js' +} from './nodes/identity.ts' +import type { Node } from './nodes/Node.ts' +import type { Pair } from './nodes/Pair.ts' +import type { Scalar } from './nodes/Scalar.ts' +import type { YAMLMap } from './nodes/YAMLMap.ts' +import type { YAMLSeq } from './nodes/YAMLSeq.ts' const BREAK = Symbol('break visit') const SKIP = Symbol('skip children') diff --git a/tests/clone.ts b/tests/clone.ts index a10e1c4e..63dfb11a 100644 --- a/tests/clone.ts +++ b/tests/clone.ts @@ -1,5 +1,6 @@ -import { isAlias, isScalar, parseDocument, Scalar, visit, YAMLMap } from 'yaml' -import { source } from './_utils' +import type { Scalar, YAMLMap } from 'yaml' +import { isAlias, isScalar, parseDocument, visit } from 'yaml' +import { source } from './_utils.ts' describe('doc.clone()', () => { test('has expected members', () => { diff --git a/tests/collection-access.ts b/tests/collection-access.ts index ba30e7e1..ec0ed50b 100644 --- a/tests/collection-access.ts +++ b/tests/collection-access.ts @@ -1,14 +1,14 @@ import { Document, - parseDocument, Pair, - Scalar, - YAMLMap, - YAMLOMap, - YAMLSeq, - YAMLSet, + type Scalar, + type YAMLMap, + type YAMLOMap, + type YAMLSeq, + type YAMLSet, + isMap, isSeq, - isMap + parseDocument } from 'yaml' describe('Map', () => { diff --git a/tests/cst.ts b/tests/cst.ts index 3580c959..b7b5f26f 100644 --- a/tests/cst.ts +++ b/tests/cst.ts @@ -1,5 +1,5 @@ import { CST, Parser } from 'yaml' -import { source } from './_utils' +import { source } from './_utils.ts' function cstDoc(src: string) { const tokens = Array.from(new Parser().parse(src)) diff --git a/tests/directives.ts b/tests/directives.ts index 1d6d2a1e..058875ec 100644 --- a/tests/directives.ts +++ b/tests/directives.ts @@ -1,5 +1,6 @@ -import { parseDocument, Scalar } from 'yaml' -import { source } from './_utils' +import type { Scalar } from 'yaml' +import { parseDocument } from 'yaml' +import { source } from './_utils.ts' describe('%TAG', () => { test('parse local tags', () => { diff --git a/tests/doc/YAML-1.1.spec.ts b/tests/doc/YAML-1.1.spec.ts index 06016882..327b493d 100644 --- a/tests/doc/YAML-1.1.spec.ts +++ b/tests/doc/YAML-1.1.spec.ts @@ -1,4 +1,4 @@ -import { source } from '../_utils' +import { source } from '../_utils.ts' import { parseAllDocuments } from 'yaml' test('Use preceding directives if none defined', () => { diff --git a/tests/doc/anchors.ts b/tests/doc/anchors.ts index 70a44da7..39460832 100644 --- a/tests/doc/anchors.ts +++ b/tests/doc/anchors.ts @@ -1,4 +1,5 @@ -import { Alias, Document, parse, parseDocument, YAMLMap, YAMLSeq } from 'yaml' +import type { Alias, YAMLMap, YAMLSeq } from 'yaml' +import { Document, parse, parseDocument } from 'yaml' test('basic', () => { const src = `- &a 1\n- *a\n` diff --git a/tests/doc/comments.ts b/tests/doc/comments.ts index aca037ca..22bfdada 100644 --- a/tests/doc/comments.ts +++ b/tests/doc/comments.ts @@ -1,4 +1,4 @@ -import { source } from '../_utils' +import { source } from '../_utils.ts' import * as YAML from 'yaml' describe('parse comments', () => { diff --git a/tests/doc/createNode.ts b/tests/doc/createNode.ts index af586a2f..5b070fd8 100644 --- a/tests/doc/createNode.ts +++ b/tests/doc/createNode.ts @@ -1,5 +1,6 @@ -import { Alias, Document, Node, Scalar, YAMLMap, YAMLSeq } from 'yaml' -import { source } from '../_utils' +import type { Alias, Node } from 'yaml' +import { Document, Scalar, YAMLMap, YAMLSeq } from 'yaml' +import { source } from '../_utils.ts' describe('createNode(value)', () => { test('boolean', () => { diff --git a/tests/doc/errors.ts b/tests/doc/errors.ts index 93800d2b..e18c6402 100644 --- a/tests/doc/errors.ts +++ b/tests/doc/errors.ts @@ -1,5 +1,5 @@ import * as YAML from 'yaml' -import { source } from '../_utils' +import { source } from '../_utils.ts' describe('tabs as indentation', () => { test('fail on map value indented with tab', () => { diff --git a/tests/doc/foldFlowLines.ts b/tests/doc/foldFlowLines.ts index 6c225dab..3068b7cf 100644 --- a/tests/doc/foldFlowLines.ts +++ b/tests/doc/foldFlowLines.ts @@ -1,6 +1,7 @@ import * as YAML from 'yaml' -import { foldFlowLines as fold, FoldOptions } from 'yaml/util' -import { source } from '../_utils' +import type { FoldOptions } from 'yaml/util' +import { foldFlowLines as fold } from 'yaml/util' +import { source } from '../_utils.ts' const FOLD_FLOW = 'flow' const FOLD_QUOTED = 'quoted' diff --git a/tests/doc/parse.ts b/tests/doc/parse.ts index a9fc9bed..24655efa 100644 --- a/tests/doc/parse.ts +++ b/tests/doc/parse.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs' import { resolve } from 'path' import * as YAML from 'yaml' -import { source } from '../_utils' +import { source } from '../_utils.ts' describe('scalars', () => { test('empty block scalar at end of document', () => { diff --git a/tests/doc/stringify.ts b/tests/doc/stringify.ts index b49d334c..82e18b85 100644 --- a/tests/doc/stringify.ts +++ b/tests/doc/stringify.ts @@ -1,4 +1,4 @@ -import { source } from '../_utils' +import { source } from '../_utils.ts' import * as YAML from 'yaml' import { Pair, Scalar } from 'yaml' diff --git a/tests/doc/types.ts b/tests/doc/types.ts index c2627d53..8c982e8a 100644 --- a/tests/doc/types.ts +++ b/tests/doc/types.ts @@ -1,22 +1,22 @@ import { - CollectionTag, + type CollectionTag, Document, - DocumentOptions, - Node, - parse, - ParsedNode, + type DocumentOptions, + type Node, parseDocument as origParseDocument, - ParseOptions, + parse, + type ParsedNode, + type ParseOptions, Scalar, - ScalarTag, + type ScalarTag, Schema, - SchemaOptions, + type SchemaOptions, stringify, YAMLMap, YAMLSeq } from 'yaml' import { seqTag, stringifyString, stringTag } from 'yaml/util' -import { source } from '../_utils' +import { source } from '../_utils.ts' const parseDocument = ( source: string, diff --git a/tests/node-to-js.ts b/tests/node-to-js.ts index 552ce3a4..bc392b25 100644 --- a/tests/node-to-js.ts +++ b/tests/node-to-js.ts @@ -1,5 +1,6 @@ -import { parseDocument, YAMLMap, YAMLSeq } from 'yaml' -import { source } from './_utils' +import type { YAMLMap, YAMLSeq } from 'yaml' +import { parseDocument } from 'yaml' +import { source } from './_utils.ts' describe('scalars', () => { test('plain', () => { diff --git a/tests/stream.ts b/tests/stream.ts index 3f9739d5..b4e44c34 100644 --- a/tests/stream.ts +++ b/tests/stream.ts @@ -1,4 +1,5 @@ -import { Composer, Document, Parser, parseDocument } from 'yaml' +import type { Document } from 'yaml' +import { Composer, Parser, parseDocument } from 'yaml' const src = ` #c0\n \n diff --git a/tests/visit.ts b/tests/visit.ts index 610ccb61..28e1c209 100644 --- a/tests/visit.ts +++ b/tests/visit.ts @@ -1,4 +1,5 @@ -import { Document, isSeq, parseDocument, Scalar, visit, visitAsync } from 'yaml' +import type { Scalar } from 'yaml' +import { Document, isSeq, parseDocument, visit, visitAsync } from 'yaml' const coll = { items: {} } diff --git a/tests/yaml-test-suite.ts b/tests/yaml-test-suite.ts index 194a7a98..04783291 100644 --- a/tests/yaml-test-suite.ts +++ b/tests/yaml-test-suite.ts @@ -1,8 +1,9 @@ import { readdirSync, readFileSync } from 'fs' import { resolve } from 'path' -import { CST, Document, Lexer, parse, parseAllDocuments, Parser } from 'yaml' -import { testEvents } from '../src/test-events' // no public export +import type { Document } from 'yaml' +import { CST, Lexer, parse, parseAllDocuments, Parser } from 'yaml' +import { testEvents } from '../src/test-events.ts' // no public export type TestCase = { yaml: string diff --git a/tsconfig.json b/tsconfig.json index e735a19e..c7338f45 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "outDir": "dist", + "rewriteRelativeImportExtensions": true, "rootDir": "src", "strict": true, "target": "ES2020",