Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop deprecated end points, members, options & defaults #171

Merged
merged 9 commits into from May 17, 2020
2 changes: 0 additions & 2 deletions browser/map.js

This file was deleted.

2 changes: 0 additions & 2 deletions browser/pair.js

This file was deleted.

2 changes: 0 additions & 2 deletions browser/scalar.js

This file was deleted.

9 changes: 0 additions & 9 deletions browser/schema.js

This file was deleted.

2 changes: 0 additions & 2 deletions browser/seq.js

This file was deleted.

8 changes: 0 additions & 8 deletions browser/types/binary.js

This file was deleted.

3 changes: 0 additions & 3 deletions browser/types/omap.js

This file was deleted.

3 changes: 0 additions & 3 deletions browser/types/pairs.js

This file was deleted.

3 changes: 0 additions & 3 deletions browser/types/set.js

This file was deleted.

10 changes: 0 additions & 10 deletions browser/types/timestamp.js

This file was deleted.

2 changes: 1 addition & 1 deletion docs/03_options.md
Expand Up @@ -110,4 +110,4 @@ These options objects are also exported individually from `'yaml/types'`.

## Silencing Warnings

By default, the library will emit warnings for uses of deprecated APIs and as required by the YAML spec during parsing. If you'd like to silence these, define a global variable `YAML_SILENCE_WARNINGS` with a true-ish value. To silence only deprecation warnings, use `YAML_SILENCE_DEPRECATION_WARNINGS`. These values may also be set in `process.env`.
By default, the library will emit warnings as required by the YAML spec during parsing. If you'd like to silence these, define a global or `process.env` variable `YAML_SILENCE_WARNINGS` with a true-ish value.
2 changes: 0 additions & 2 deletions map.js

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "yaml",
"version": "1.10.0",
"version": "2.0.0-alpha",
"license": "ISC",
"author": "Eemeli Aro <eemeli@gmail.com>",
"repository": "github:eemeli/yaml",
Expand Down Expand Up @@ -42,6 +42,7 @@
},
"exports": {
".": "./index.js",
"./package.json": "./package.json",
"./parse-cst": "./parse-cst.js",
"./types": [
{
Expand All @@ -54,8 +55,7 @@
"import": "./util.mjs"
},
"./util.js"
],
"./": "./"
]
},
"scripts": {
"build": "npm run build:node && npm run build:browser",
Expand Down
2 changes: 0 additions & 2 deletions pair.js

This file was deleted.

1 change: 0 additions & 1 deletion rollup.browser-config.js
Expand Up @@ -3,7 +3,6 @@ import babel from '@rollup/plugin-babel'
export default {
input: {
index: 'src/index.js',
'legacy-exports': 'src/legacy-exports.js',
'parse-cst': 'src/cst/parse.js',
types: 'src/types.js',
util: 'src/util.js'
Expand Down
1 change: 0 additions & 1 deletion rollup.node-config.js
Expand Up @@ -3,7 +3,6 @@ import babel from '@rollup/plugin-babel'
export default {
input: {
index: 'src/index.js',
'legacy-exports': 'src/legacy-exports.js',
'parse-cst': 'src/cst/parse.js',
'test-events': 'src/test-events.js',
types: 'src/types.js',
Expand Down
2 changes: 0 additions & 2 deletions scalar.js

This file was deleted.

9 changes: 0 additions & 9 deletions schema.js

This file was deleted.

2 changes: 0 additions & 2 deletions seq.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/doc/Document.js
@@ -1,4 +1,5 @@
import { Collection, Node, Scalar, isEmptyPath, toJSON } from '../ast/index.js'
import { defaultTagPrefix } from '../constants.js'
import { YAMLError } from '../errors.js'
import { documentOptions } from '../options.js'
import { addComment } from '../stringify/addComment.js'
Expand Down Expand Up @@ -152,7 +153,7 @@ export class Document {

listNonDefaultTags() {
return listTagNames(this.contents).filter(
t => t.indexOf(Schema.defaultPrefix) !== 0
t => t.indexOf(defaultTagPrefix) !== 0
)
}

Expand Down
28 changes: 3 additions & 25 deletions src/doc/Schema.js
@@ -1,44 +1,22 @@
import { Pair } from '../ast/Pair.js'
import { defaultTagPrefix, defaultTags } from '../constants.js'
import { schemas, tags } from '../tags/index.js'
import { warnOptionDeprecation } from '../warnings.js'
import { createNode } from './createNode.js'
import { getSchemaTags } from './getSchemaTags.js'

const sortMapEntriesByKey = (a, b) =>
a.key < b.key ? -1 : a.key > b.key ? 1 : 0

export class Schema {
static defaultPrefix = defaultTagPrefix // TODO: remove in v2
static defaultTags = defaultTags // TODO: remove in v2

constructor({
customTags,
merge,
schema,
sortMapEntries,
tags: deprecatedCustomTags
}) {
constructor({ customTags, merge, schema, sortMapEntries }) {
this.merge = !!merge
this.name = schema
this.sortMapEntries =
sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null
if (!customTags && deprecatedCustomTags)
warnOptionDeprecation('tags', 'customTags')
this.tags = getSchemaTags(
schemas,
tags,
customTags || deprecatedCustomTags,
schema
)
this.tags = getSchemaTags(schemas, tags, customTags, schema)
}

createNode(value, wrapScalars, tagName, ctx) {
const baseCtx = {
defaultPrefix: Schema.defaultPrefix,
schema: this,
wrapScalars
}
const baseCtx = { schema: this, wrapScalars }
const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx
return createNode(value, tagName, createCtx)
}
Expand Down
14 changes: 4 additions & 10 deletions src/doc/createNode.js
@@ -1,6 +1,7 @@
import { Alias } from '../ast/Alias.js'
import { Node } from '../ast/Node.js'
import { Scalar } from '../ast/Scalar.js'
import { defaultTagPrefix } from '../constants.js'
import { map } from '../tags/failsafe/map.js'
import { seq } from '../tags/failsafe/seq.js'

Expand All @@ -11,21 +12,14 @@ function findTagObject(value, tagName, tags) {
if (!tagObj) throw new Error(`Tag ${tagName} not found`)
return tagObj
}

// TODO: deprecate/remove class check
return tags.find(
t =>
((t.identify && t.identify(value)) ||
(t.class && value instanceof t.class)) &&
!t.format
)
return tags.find(t => t.identify && t.identify(value) && !t.format)
}

export function createNode(value, tagName, ctx) {
if (value instanceof Node) return value
const { defaultPrefix, onTagObj, prevObjects, schema, wrapScalars } = ctx
const { onTagObj, prevObjects, schema, wrapScalars } = ctx
if (tagName && tagName.startsWith('!!'))
tagName = defaultPrefix + tagName.slice(2)
tagName = defaultTagPrefix + tagName.slice(2)

let tagObj = findTagObject(value, tagName, schema.tags)
if (!tagObj) {
Expand Down
7 changes: 0 additions & 7 deletions src/legacy-exports.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/options.js
Expand Up @@ -17,7 +17,7 @@ export const defaultOptions = {
keepBlobsInJSON: true,
mapAsMap: false,
maxAliasCount: 100,
prettyErrors: false, // TODO Set true in v2
prettyErrors: true,
simpleKeys: false,
version: '1.2'
}
Expand Down
6 changes: 1 addition & 5 deletions src/stringify/stringify.js
Expand Up @@ -16,11 +16,7 @@ function getTagObject(tags, item) {
let tagObj, obj
if (item instanceof Scalar) {
obj = item.value
// TODO: deprecate/remove class check
const match = tags.filter(
t =>
(t.identify && t.identify(obj)) || (t.class && obj instanceof t.class)
)
const match = tags.filter(t => t.identify && t.identify(obj))
tagObj =
match.find(t => t.format === item.format) || match.find(t => !t.format)
} else {
Expand Down
53 changes: 11 additions & 42 deletions src/warnings.js
@@ -1,51 +1,20 @@
/* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
/* global console, process, YAML_SILENCE_WARNINGS */

function shouldWarn(deprecation) {
const env = (typeof process !== 'undefined' && process.env) || {}
export function warn(warning, type) {
if (typeof YAML_SILENCE_WARNINGS !== 'undefined' && YAML_SILENCE_WARNINGS)
return

if (deprecation) {
if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined')
return !YAML_SILENCE_DEPRECATION_WARNINGS
return !env.YAML_SILENCE_DEPRECATION_WARNINGS
}
if (typeof process !== 'undefined') {
if (process.env.YAML_SILENCE_WARNINGS) return

if (typeof YAML_SILENCE_WARNINGS !== 'undefined')
return !YAML_SILENCE_WARNINGS
return !env.YAML_SILENCE_WARNINGS
}

export function warn(warning, type) {
if (shouldWarn(false)) {
const emit = typeof process !== 'undefined' && process.emitWarning
// This will throw in Jest if `warning` is an Error instance due to
// https://github.com/facebook/jest/issues/2549
if (emit) emit(warning, type)
else {
// eslint-disable-next-line no-console
console.warn(type ? `${type}: ${warning}` : warning)
if (process.emitWarning) {
process.emitWarning(warning, type)
return
}
}
}

export function warnFileDeprecation(filename) {
if (shouldWarn(true)) {
const path = filename
.replace(/.*yaml[/\\]/i, '')
.replace(/\.js$/, '')
.replace(/\\/g, '/')
warn(
`The endpoint 'yaml/${path}' will be removed in a future release.`,
'DeprecationWarning'
)
}
}

const warned = {}
export function warnOptionDeprecation(name, alternative) {
if (!warned[name] && shouldWarn(true)) {
warned[name] = true
let msg = `The option '${name}' will be removed in a future release`
msg += alternative ? `, use '${alternative}' instead.` : '.'
warn(msg, 'DeprecationWarning')
}
// eslint-disable-next-line no-console
console.warn(type ? `${type}: ${warning}` : warning)
}
5 changes: 4 additions & 1 deletion tests/doc/YAML-1.2.spec.js
Expand Up @@ -1833,18 +1833,21 @@ matches %: 20`,
}
}

let origFoldOptions
let origFoldOptions, origPrettyErrors

beforeAll(() => {
origFoldOptions = YAML.scalarOptions.str.fold
YAML.scalarOptions.str.fold = {
lineWidth: 20,
minContentWidth: 0
}
origPrettyErrors = YAML.defaultOptions.prettyErrors
YAML.defaultOptions.prettyErrors = false
})

afterAll(() => {
YAML.scalarOptions.str.fold = origFoldOptions
YAML.defaultOptions.prettyErrors = origPrettyErrors
})

for (const section in spec) {
Expand Down