Skip to content

Commit

Permalink
feat!: switch to esm (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored Oct 14, 2022
1 parent 1b2a40a commit a23343e
Show file tree
Hide file tree
Showing 97 changed files with 945 additions and 669 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "import"],
"env": { "node": true },
"rules": {
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-constant-condition": ["error", { "checkLoops": false }]
"no-constant-condition": ["error", { "checkLoops": false }],
"import/extensions": ["error", "always"]
}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ yarn add yaml-unist-parser
## Usage

```ts
const { parse } = require("yaml-unist-parser");
import { parse } from "yaml-unist-parser";

const ast = parse(`
- hello
Expand Down
21 changes: 16 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
module.exports = {
export default {
testEnvironment: "node",
moduleFileExtensions: ["ts", "js", "json"],
testMatch: ["**/tests/**/*.ts", "**/*.test.ts"],
transform: { "\\.ts$": "ts-jest" },
extensionsToTreatAsEsm: ['.ts'],
transform: {
'\\.ts$': [
'ts-jest',
{
diagnostics: true,
useESM: true,
},
],
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
snapshotSerializers: ['jest-snapshot-serializer-raw'],
coverageReporters: ["lcov", "text-summary"],
collectCoverage: !!process.env.CI,
collectCoverage: true,
collectCoverageFrom: ["src/**/*.ts"],
coveragePathIgnorePatterns: [
"src/index.ts",
Expand All @@ -15,8 +27,7 @@ module.exports = {
coverageThreshold: {
global: {
branches: 100,
// TODO: 100
functions: 98,
functions: 100,
lines: 100,
statements: 100
}
Expand Down
31 changes: 18 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"unist",
"yaml"
],
"main": "lib/index.js",
"type": "module",
"types": "lib/index.d.ts",
"exports": {
".": "./lib/index.js",
"./*": "./"
},
"repository": "https://github.com/ikatyang/yaml-unist-parser",
"homepage": "https://github.com/ikatyang/yaml-unist-parser#readme",
"author": {
Expand All @@ -19,35 +23,36 @@
"scripts": {
"prepublish": "patch-package && yarn run build",
"lint": "run-p lint:*",
"lint:eslint": "eslint --ext=.ts .",
"lint:eslint": "eslint --ext=.ts,.cjs,.mjs .",
"lint:prettier": "prettier --check src",
"fix": "run-s fix:*",
"fix:eslint": "yarn lint:eslint --fix",
"fix:prettier": "yarn lint:prettier --write",
"test": "jest",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"prebuild": "rm -rf ./lib",
"build": "tsc -p ./tsconfig.build.json",
"release": "standard-version"
"release": "yarn build && standard-version"
},
"dependencies": {
"lines-and-columns": "^2.0.3",
"tslib": "^2.4.0",
"yaml": "^1.10.0"
},
"devDependencies": {
"@types/jest": "29.1.0",
"@types/node": "18.7.23",
"@typescript-eslint/eslint-plugin": "5.38.1",
"@typescript-eslint/parser": "5.38.1",
"eslint": "8.24.0",
"eslint-config-prettier": "^8.5.0",
"jest": "29.1.1",
"@types/jest": "29.1.2",
"@types/node": "18.8.5",
"@typescript-eslint/eslint-plugin": "5.40.0",
"@typescript-eslint/parser": "5.40.0",
"eslint": "8.25.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"jest": "29.1.2",
"jest-snapshot-serializer-raw": "1.2.0",
"npm-run-all": "^4.1.5",
"npm-run-all": "4.1.5",
"patch-package": "6.4.7",
"prettier": "2.7.1",
"standard-version": "9.5.0",
"ts-jest": "29.0.2",
"ts-jest": "29.0.3",
"typescript": "4.8.4"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/attach.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { testCases, TestCaseSingle } from "./helpers";
import { Comment, Root } from "./types";
import { testCases, TestCaseSingle } from "./helpers.js";
import { Comment, Root } from "./types.js";

// example from http://nodeca.github.io/js-yaml/
const jsYamlExample = `
Expand Down
6 changes: 3 additions & 3 deletions src/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
Root,
TrailingCommentAttachable,
YamlUnistNode,
} from "./types";
import { defineParents } from "./utils/define-parents";
import { getPointText } from "./utils/get-point-text";
} from "./types.js";
import { defineParents } from "./utils/define-parents.js";
import { getPointText } from "./utils/get-point-text.js";

interface NodeTable {
[line: number]: {
Expand Down
6 changes: 3 additions & 3 deletions src/factories/alias.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Alias, Content, Position } from "../types";
import { createCommentAttachable } from "./comment-attachable";
import { createNode } from "./node";
import { Alias, Content, Position } from "../types.js";
import { createCommentAttachable } from "./comment-attachable.js";
import { createNode } from "./node.js";

export function createAlias(
position: Position,
Expand Down
4 changes: 2 additions & 2 deletions src/factories/anchor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Anchor, Position } from "../types";
import { createNode } from "./node";
import { Anchor, Position } from "../types.js";
import { createNode } from "./node.js";

export function createAnchor(position: Position, value: string): Anchor {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/factories/block-folded.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockFolded, BlockValue } from "../types";
import { BlockFolded, BlockValue } from "../types.js";

export function createBlockFolded(blockValue: BlockValue): BlockFolded {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/factories/block-literal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockLiteral, BlockValue } from "../types";
import { BlockLiteral, BlockValue } from "../types.js";

export function createBlockLiteral(blockValue: BlockValue): BlockLiteral {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/factories/block-value.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BlockValue, Comment, Content, Position } from "../types";
import { createLeadingCommentAttachable } from "./leading-comment-attachable";
import { createNode } from "./node";
import { BlockValue, Comment, Content, Position } from "../types.js";
import { createLeadingCommentAttachable } from "./leading-comment-attachable.js";
import { createNode } from "./node.js";

export function createBlockValue(
position: Position,
Expand Down
6 changes: 3 additions & 3 deletions src/factories/comment-attachable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommentAttachable } from "../types";
import { createLeadingCommentAttachable } from "./leading-comment-attachable";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable";
import { CommentAttachable } from "../types.js";
import { createLeadingCommentAttachable } from "./leading-comment-attachable.js";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable.js";

export function createCommentAttachable(): CommentAttachable {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/factories/comment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Position } from "../types";
import { createNode } from "./node";
import { Position } from "../types.js";
import { createNode } from "./node.js";

export function createComment(position: Position, value: string) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/factories/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Anchor, Comment, Content, Tag } from "../types";
import { Anchor, Comment, Content, Tag } from "../types.js";

export function createContent(
tag: Tag | null,
Expand Down
6 changes: 3 additions & 3 deletions src/factories/directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive, Position } from "../types";
import { createCommentAttachable } from "./comment-attachable";
import { createNode } from "./node";
import { Directive, Position } from "../types.js";
import { createCommentAttachable } from "./comment-attachable.js";
import { createNode } from "./node.js";

export function createDirective(
position: Position,
Expand Down
6 changes: 3 additions & 3 deletions src/factories/document-body.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Comment, ContentNode, DocumentBody, Position } from "../types";
import { createEndCommentAttachable } from "./end-comment-attachable";
import { createNode } from "./node";
import { Comment, ContentNode, DocumentBody, Position } from "../types.js";
import { createEndCommentAttachable } from "./end-comment-attachable.js";
import { createNode } from "./node.js";

export function createDocumentBody(
position: Position,
Expand Down
8 changes: 4 additions & 4 deletions src/factories/document-head.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Comment, Directive, DocumentHead, Position } from "../types";
import { createEndCommentAttachable } from "./end-comment-attachable";
import { createNode } from "./node";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable";
import { Comment, Directive, DocumentHead, Position } from "../types.js";
import { createEndCommentAttachable } from "./end-comment-attachable.js";
import { createNode } from "./node.js";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable.js";

export function createDocumentHead(
position: Position,
Expand Down
6 changes: 3 additions & 3 deletions src/factories/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
DocumentBody,
DocumentHead,
Position,
} from "../types";
import { createNode } from "./node";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable";
} from "../types.js";
import { createNode } from "./node.js";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable.js";

export function createDocument(
position: Position,
Expand Down
2 changes: 1 addition & 1 deletion src/factories/end-comment-attachable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Comment, EndCommentAttachable } from "../types";
import { Comment, EndCommentAttachable } from "../types.js";

export function createEndCommentAttachable(
endComments: Comment[] = [],
Expand Down
2 changes: 1 addition & 1 deletion src/factories/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Position, YAMLSyntaxError } from "../types";
import { Position, YAMLSyntaxError } from "../types.js";

export function createError(
message: string,
Expand Down
13 changes: 9 additions & 4 deletions src/factories/flow-collection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Content, FlowMappingItem, FlowSequenceItem, Position } from "../types";
import { createCommentAttachable } from "./comment-attachable";
import { createEndCommentAttachable } from "./end-comment-attachable";
import { createNode } from "./node";
import {
Content,
FlowMappingItem,
FlowSequenceItem,
Position,
} from "../types.js";
import { createCommentAttachable } from "./comment-attachable.js";
import { createEndCommentAttachable } from "./end-comment-attachable.js";
import { createNode } from "./node.js";

export function createFlowCollection<
T extends FlowMappingItem | FlowSequenceItem,
Expand Down
11 changes: 8 additions & 3 deletions src/factories/flow-mapping-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { FlowMappingItem, MappingKey, MappingValue, Position } from "../types";
import { createLeadingCommentAttachable } from "./leading-comment-attachable";
import { createNode } from "./node";
import {
FlowMappingItem,
MappingKey,
MappingValue,
Position,
} from "../types.js";
import { createLeadingCommentAttachable } from "./leading-comment-attachable.js";
import { createNode } from "./node.js";

export function createFlowMappingItem(
position: Position,
Expand Down
4 changes: 2 additions & 2 deletions src/factories/flow-mapping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Content, FlowMapping, FlowMappingItem, Position } from "../types";
import { createFlowCollection } from "./flow-collection";
import { Content, FlowMapping, FlowMappingItem, Position } from "../types.js";
import { createFlowCollection } from "./flow-collection.js";

export function createFlowMapping(
position: Position,
Expand Down
4 changes: 2 additions & 2 deletions src/factories/flow-sequence-item.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentNode, FlowSequenceItem, Position } from "../types";
import { createNode } from "./node";
import { ContentNode, FlowSequenceItem, Position } from "../types.js";
import { createNode } from "./node.js";

export function createFlowSequenceItem(
position: Position,
Expand Down
4 changes: 2 additions & 2 deletions src/factories/flow-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
FlowSequence,
FlowSequenceItem,
Position,
} from "../types";
import { createFlowCollection } from "./flow-collection";
} from "../types.js";
import { createFlowCollection } from "./flow-collection.js";

export function createFlowSequence(
position: Position,
Expand Down
2 changes: 1 addition & 1 deletion src/factories/leading-comment-attachable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LeadingCommentAttachable } from "../types";
import { LeadingCommentAttachable } from "../types.js";

export function createLeadingCommentAttachable(): LeadingCommentAttachable {
return {
Expand Down
6 changes: 3 additions & 3 deletions src/factories/mapping-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MappingItem, MappingKey, MappingValue, Position } from "../types";
import { createLeadingCommentAttachable } from "./leading-comment-attachable";
import { createNode } from "./node";
import { MappingItem, MappingKey, MappingValue, Position } from "../types.js";
import { createLeadingCommentAttachable } from "./leading-comment-attachable.js";
import { createNode } from "./node.js";

export function createMappingItem(
position: Position,
Expand Down
8 changes: 4 additions & 4 deletions src/factories/mapping-key.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContentNode, MappingKey, Position } from "../types";
import { createEndCommentAttachable } from "./end-comment-attachable";
import { createNode } from "./node";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable";
import { ContentNode, MappingKey, Position } from "../types.js";
import { createEndCommentAttachable } from "./end-comment-attachable.js";
import { createNode } from "./node.js";
import { createTrailingCommentAttachable } from "./trailing-comment-attachable.js";

export function createMappingKey(
position: Position,
Expand Down
8 changes: 4 additions & 4 deletions src/factories/mapping-value.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContentNode, MappingValue, Position } from "../types";
import { createCommentAttachable } from "./comment-attachable";
import { createEndCommentAttachable } from "./end-comment-attachable";
import { createNode } from "./node";
import { ContentNode, MappingValue, Position } from "../types.js";
import { createCommentAttachable } from "./comment-attachable.js";
import { createEndCommentAttachable } from "./end-comment-attachable.js";
import { createNode } from "./node.js";

export function createMappingValue(
position: Position,
Expand Down
6 changes: 3 additions & 3 deletions src/factories/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Content, Mapping, MappingItem, Position } from "../types";
import { createLeadingCommentAttachable } from "./leading-comment-attachable";
import { createNode } from "./node";
import { Content, Mapping, MappingItem, Position } from "../types.js";
import { createLeadingCommentAttachable } from "./leading-comment-attachable.js";
import { createNode } from "./node.js";

export function createMapping(
position: Position,
Expand Down
2 changes: 1 addition & 1 deletion src/factories/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Position } from "../types";
import { Position } from "../types.js";

export function createNode<T extends string>(type: T, position: Position) {
return { type, position };
Expand Down
6 changes: 3 additions & 3 deletions src/factories/plain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Content, Plain, Position } from "../types";
import { createCommentAttachable } from "./comment-attachable";
import { createNode } from "./node";
import { Content, Plain, Position } from "../types.js";
import { createCommentAttachable } from "./comment-attachable.js";
import { createNode } from "./node.js";

export function createPlain(
position: Position,
Expand Down
Loading

0 comments on commit a23343e

Please sign in to comment.