Skip to content

Commit

Permalink
chore: upgrade to yaml@^1.10 (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang authored May 23, 2020
1 parent c7568cb commit 2cf5008
Show file tree
Hide file tree
Showing 34 changed files with 300 additions and 376 deletions.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
},
"license": "MIT",
"scripts": {
"fix-types": "replace '(orig(Start|End|Offset))\\?:' '$1:' node_modules/@types/yaml/index.d.ts",
"prepublish": "yarn run fix-types && yarn run build",
"prepublish": "patch-package && yarn run build",
"lint": "tslint -p ./tsconfig.json",
"test": "jest",
"prebuild": "rm -rf ./lib",
Expand All @@ -28,16 +27,15 @@
"dependencies": {
"lines-and-columns": "^1.1.6",
"tslib": "^1.10.0",
"yaml": "^1.7.1"
"yaml": "^1.10.0"
},
"devDependencies": {
"@types/jest": "23.3.14",
"@types/node": "6.14.9",
"@types/yaml": "1.2.0",
"jest": "23.6.0",
"jest-snapshot-serializer-raw": "1.1.0",
"patch-package": "6.2.2",
"prettier": "1.18.2",
"replace": "1.1.5",
"standard-version": "4.4.0",
"ts-jest": "23.10.5",
"tslint": "5.20.1",
Expand Down
65 changes: 65 additions & 0 deletions patches/yaml+1.10.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
diff --git a/node_modules/yaml/index.d.ts b/node_modules/yaml/index.d.ts
index 36aa3c6..2ffad3b 100644
--- a/node_modules/yaml/index.d.ts
+++ b/node_modules/yaml/index.d.ts
@@ -205,7 +205,7 @@ export class Document extends Collection {
*/
anchors: Document.Anchors
/** The document contents. */
- contents: any
+ contents: AST.BlockFolded | AST.BlockLiteral | AST.BlockMap | AST.BlockSeq | AST.FlowMap | AST.FlowSeq | AST.PlainValue | AST.QuoteDouble | AST.QuoteSingle | Alias | null
/** Errors encountered during parsing. */
errors: YAMLError[]
/**
@@ -260,7 +260,6 @@ export class Document extends Collection {

export namespace Document {
interface Parsed extends Document {
- contents: Node | null
/** The schema used with the document. */
schema: Schema
}
diff --git a/node_modules/yaml/parse-cst.d.ts b/node_modules/yaml/parse-cst.d.ts
index bd8a5b4..1c764a9 100644
--- a/node_modules/yaml/parse-cst.d.ts
+++ b/node_modules/yaml/parse-cst.d.ts
@@ -10,8 +10,8 @@ export namespace CST {
interface Range {
start: number
end: number
- origStart?: number
- origEnd?: number
+ origStart: number
+ origEnd: number
isEmpty(): boolean
}

@@ -148,7 +148,7 @@ export namespace CST {
interface FlowChar {
char: '{' | '}' | '[' | ']' | ',' | '?' | ':'
offset: number
- origOffset?: number
+ origOffset: number
}

interface FlowCollection extends Node {
diff --git a/node_modules/yaml/types.d.ts b/node_modules/yaml/types.d.ts
index 411e74e..c13f624 100644
--- a/node_modules/yaml/types.d.ts
+++ b/node_modules/yaml/types.d.ts
@@ -395,13 +395,13 @@ export namespace AST {

interface FlowSeq extends YAMLSeq {
type: Type.FLOW_SEQ
- items: Array<Node>
+ items: Array<FlowMap | FlowSeq | QuoteDouble | QuoteSingle | PlainValue | Alias | Pair>
cstNode?: CST.FlowSeq
}

interface BlockSeq extends YAMLSeq {
type: Type.SEQ
- items: Array<Node | null>
+ items: Array<FlowMap | FlowSeq | QuoteDouble | QuoteSingle | PlainValue | Alias | null>
cstNode?: CST.Seq
}
}
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { wrap } from "jest-snapshot-serializer-raw";
import * as YAML from "yaml";
import { parse } from "./parse";
import {
Anchor,
Expand All @@ -10,6 +9,7 @@ import {
Tag,
YamlUnistNode,
} from "./types";
import * as YAML from "./yaml";

export type Arrayable<T> = T | T[];

Expand Down
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import LinesAndColumns from "lines-and-columns";
import * as YAML from "yaml";
import { attachComments } from "./attach";
import { createRoot } from "./factories/root";
import { removeCstBlankLine } from "./preprocess";
Expand All @@ -12,6 +11,7 @@ import { Comment, Root } from "./types";
import { addOrigRange } from "./utils/add-orig-range";
import { removeFakeNodes } from "./utils/remove-fake-nodes";
import { updatePositions } from "./utils/update-positions";
import * as YAML from "./yaml";

export function parse(text: string): Root {
const cst = YAML.parseCST(text);
Expand Down
2 changes: 1 addition & 1 deletion src/preprocess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as YAML from "yaml";
import * as YAML from "./yaml";

type YamlCstNode =
| YAML.cst.Alias
Expand Down
2 changes: 1 addition & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import LinesAndColumns from "lines-and-columns";
import * as YAML from "yaml";
import { transformAlias } from "./transforms/alias";
import { transformBlockFolded } from "./transforms/block-folded";
import { transformBlockLiteral } from "./transforms/block-literal";
Expand Down Expand Up @@ -33,6 +32,7 @@ import {
Sequence,
YamlUnistNode,
} from "./types";
import * as YAML from "./yaml";

export type YamlNode =
| null
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/__snapshots__/document.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,8 @@ root (1:1 ~ 3:4)
</root>
`;
exports[`Document is not valid YAML (bad indentation?) 1`] = `
"Document is not valid YAML (bad indentation?)
exports[`Document contains trailing content not separated by a ... or --- line 1`] = `
"Document contains trailing content not separated by a ... or --- line
1 | -·123¶
2 | a:¶
| ^^^
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/alias.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as YAML from "yaml";
import { createAlias } from "../factories/alias";
import { Context } from "../transform";
import { Alias } from "../types";
import * as YAML from "../yaml";

export function transformAlias(alias: YAML.ast.Alias, context: Context): Alias {
const cstNode = alias.cstNode!;
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/block-folded.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as YAML from "yaml";
import { createBlockFolded } from "../factories/block-folded";
import { Context } from "../transform";
import { BlockFolded } from "../types";
import * as YAML from "../yaml";
import { transformAstBlockValue } from "./block-value";

export function transformBlockFolded(
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/block-literal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as YAML from "yaml";
import { createBlockLiteral } from "../factories/block-literal";
import { Context } from "../transform";
import { BlockLiteral } from "../types";
import * as YAML from "../yaml";
import { transformAstBlockValue } from "./block-value";

export function transformBlockLiteral(
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/block-value.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as YAML from "yaml";
import { createBlockValue } from "../factories/block-value";
import { Context } from "../transform";
import { BlockValue, Comment } from "../types";
import { getPointText } from "../utils/get-point-text";
import * as YAML from "../yaml";
import { transformContent } from "./content";

enum Chomping {
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/comment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as YAML from "yaml";
import { createComment } from "../factories/comment";
import { Context } from "../transform";
import { Comment } from "../types";
import * as YAML from "../yaml";

export function transformComment(
comment: YAML.cst.Comment,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/content.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as YAML from "yaml";
import { PropLeadingCharacter } from "../constants";
import { createAnchor } from "../factories/anchor";
import { createComment } from "../factories/comment";
import { createContent } from "../factories/content";
import { createTag } from "../factories/tag";
import { Context } from "../transform";
import { Anchor, Comment, Content, Tag } from "../types";
import * as YAML from "../yaml";

export function transformContent(
node: YAML.ast.Node,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/directive.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as YAML from "yaml";
import { createDirective } from "../factories/directive";
import { Context } from "../transform";
import { Directive } from "../types";
import { extractPropComments } from "../utils/extract-prop-comments";
import * as YAML from "../yaml";

export function transformDirective(
directive: YAML.cst.Directive,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/document-body.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as YAML from "yaml";
import { createDocumentBody } from "../factories/document-body";
import { Context } from "../transform";
import { Comment, ContentNode, Point } from "../types";
import { getLast } from "../utils/get-last";
import { getMatchIndex } from "../utils/get-match-index";
import { getPointText } from "../utils/get-point-text";
import * as YAML from "../yaml";

export function transformDocumentBody(
document: YAML.ast.Document,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/document-head.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as YAML from "yaml";
import { createDocumentHead } from "../factories/document-head";
import { Context } from "../transform";
import { Comment, Directive } from "../types";
import { getMatchIndex } from "../utils/get-match-index";
import * as YAML from "../yaml";
import { Range } from "./range";

export function transformDocumentHead(
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/document.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as YAML from "yaml";
import { createDocument } from "../factories/document";
import { createPosition } from "../factories/position";
import { Context } from "../transform";
import { Document } from "../types";
import * as YAML from "../yaml";
import { transformDocumentBody } from "./document-body";
import { transformDocumentHead } from "./document-head";

Expand Down
4 changes: 2 additions & 2 deletions src/transforms/error.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as YAML from "yaml";
import { createError } from "../factories/error";
import { Context } from "../transform";
import { YAMLSyntaxError } from "../types";
import * as YAML from "../yaml";

export function transformError(
error: Extract<YAML.YAMLError, SyntaxError>,
context: Context,
): YAMLSyntaxError {
// istanbul ignore next
const range = (error.source.range || error.source.valueRange)!;
const range = (error.source!.range || error.source!.valueRange)!;
return createError(
error.message,
context.text,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/flow-map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as YAML from "yaml";
import { createFlowMapping } from "../factories/flow-mapping";
import { createFlowMappingItem } from "../factories/flow-mapping-item";
import { Context } from "../transform";
Expand All @@ -7,6 +6,7 @@ import { extractComments } from "../utils/extract-comments";
import { getFlowMapItemAdditionalRanges } from "../utils/get-flow-map-item-additional-ranges";
import { getLast } from "../utils/get-last";
import { groupCstFlowCollectionItems } from "../utils/group-cst-flow-collection-items";
import * as YAML from "../yaml";
import { transformAstPair } from "./pair";

export function transformFlowMap(
Expand Down
7 changes: 5 additions & 2 deletions src/transforms/flow-seq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as YAML from "yaml";
import { createFlowMappingItem } from "../factories/flow-mapping-item";
import { createFlowSequence } from "../factories/flow-sequence";
import { createFlowSequenceItem } from "../factories/flow-sequence-item";
Expand All @@ -9,6 +8,7 @@ import { extractComments } from "../utils/extract-comments";
import { getFlowMapItemAdditionalRanges } from "../utils/get-flow-map-item-additional-ranges";
import { getLast } from "../utils/get-last";
import { groupCstFlowCollectionItems } from "../utils/group-cst-flow-collection-items";
import * as YAML from "../yaml";
import { transformAstPair } from "./pair";

export function transformFlowSeq(
Expand All @@ -24,7 +24,10 @@ export function transformFlowSeq(

const flowSequenceItems = flowSeq.items.map((item, index) => {
if (item.type !== "PAIR") {
const node = context.transformNode(item);
const node = context.transformNode(item as Exclude<
typeof item,
YAML.ast.Pair
>);
return createFlowSequenceItem(
createPosition(node.position.start, node.position.end),
node,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as YAML from "yaml";
import { createMapping } from "../factories/mapping";
import { createMappingItem } from "../factories/mapping-item";
import { createPosition } from "../factories/position";
Expand All @@ -8,6 +7,7 @@ import { createSlicer } from "../utils/create-slicer";
import { extractComments } from "../utils/extract-comments";
import { extractPropComments } from "../utils/extract-prop-comments";
import { getLast } from "../utils/get-last";
import * as YAML from "../yaml";
import { transformAstPair } from "./pair";

export function transformMap(map: YAML.ast.Map, context: Context): Mapping {
Expand Down
20 changes: 16 additions & 4 deletions src/transforms/pair.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import * as YAML from "yaml";
import { createFlowMappingItem } from "../factories/flow-mapping-item";
import { createMappingItem } from "../factories/mapping-item";
import { createMappingKey } from "../factories/mapping-key";
import { createMappingValue } from "../factories/mapping-value";
import { createEmptyPosition, createPosition } from "../factories/position";
import { Context } from "../transform";
import { FlowMappingItem, MappingItem } from "../types";
import {
Comment,
Directive,
Document,
FlowMappingItem,
MappingItem,
} from "../types";
import * as YAML from "../yaml";
import { Range } from "./range";

export function transformAstPair(
Expand Down Expand Up @@ -49,7 +55,10 @@ export function transformAstPair(
? keyContent.position.end.offset
: additionalKeyRange!.origStart + 1,
}),
keyContent,
keyContent as Exclude<
typeof keyContent,
Comment | Directive | Document
>,
)
: null;

Expand All @@ -65,7 +74,10 @@ export function transformAstPair(
? valueContent.position.end.offset
: additionalValueRange!.origStart + 1,
}),
valueContent,
valueContent as Exclude<
typeof valueContent,
Comment | Directive | Document
>,
)
: null;

Expand Down
2 changes: 1 addition & 1 deletion src/transforms/plain.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as YAML from "yaml";
import { createPlain } from "../factories/plain";
import { Context } from "../transform";
import { Plain } from "../types";
import { findLastCharIndex } from "../utils/find-last-char-index";
import * as YAML from "../yaml";

export function transformPlain(
plain: YAML.ast.PlainValue,
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/quote-double.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as YAML from "yaml";
import { createQuoteDouble } from "../factories/quote-double";
import { Context } from "../transform";
import { QuoteDouble } from "../types";
import * as YAML from "../yaml";
import { transformAstQuoteValue } from "./quote-value";

export function transformQuoteDouble(
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/quote-single.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as YAML from "yaml";
import { createQuoteSingle } from "../factories/quote-single";
import { Context } from "../transform";
import { QuoteSingle } from "../types";
import * as YAML from "../yaml";
import { transformAstQuoteValue } from "./quote-value";

export function transformQuoteSingle(
Expand Down
Loading

0 comments on commit 2cf5008

Please sign in to comment.