From 4d9487ebef6503d8897f4ae21ecf33450f2e11d5 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 13:16:28 +0300 Subject: [PATCH 1/9] Drop all deperecated entry points --- browser/map.js | 2 -- browser/pair.js | 2 -- browser/scalar.js | 2 -- browser/schema.js | 9 --------- browser/seq.js | 2 -- browser/types/binary.js | 8 -------- browser/types/omap.js | 3 --- browser/types/pairs.js | 3 --- browser/types/set.js | 3 --- browser/types/timestamp.js | 10 ---------- map.js | 2 -- pair.js | 2 -- scalar.js | 2 -- schema.js | 9 --------- seq.js | 2 -- tests/doc/errors.js | 23 ----------------------- types/binary.js | 8 -------- types/omap.js | 3 --- types/pairs.js | 3 --- types/set.js | 3 --- types/timestamp.js | 10 ---------- 21 files changed, 111 deletions(-) delete mode 100644 browser/map.js delete mode 100644 browser/pair.js delete mode 100644 browser/scalar.js delete mode 100644 browser/schema.js delete mode 100644 browser/seq.js delete mode 100644 browser/types/binary.js delete mode 100644 browser/types/omap.js delete mode 100644 browser/types/pairs.js delete mode 100644 browser/types/set.js delete mode 100644 browser/types/timestamp.js delete mode 100644 map.js delete mode 100644 pair.js delete mode 100644 scalar.js delete mode 100644 schema.js delete mode 100644 seq.js delete mode 100644 types/binary.js delete mode 100644 types/omap.js delete mode 100644 types/pairs.js delete mode 100644 types/set.js delete mode 100644 types/timestamp.js diff --git a/browser/map.js b/browser/map.js deleted file mode 100644 index 78f2ebc7..00000000 --- a/browser/map.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').YAMLMap -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/browser/pair.js b/browser/pair.js deleted file mode 100644 index b2880a25..00000000 --- a/browser/pair.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').Pair -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/browser/scalar.js b/browser/scalar.js deleted file mode 100644 index deee1b03..00000000 --- a/browser/scalar.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').Scalar -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/browser/schema.js b/browser/schema.js deleted file mode 100644 index 4139c4bf..00000000 --- a/browser/schema.js +++ /dev/null @@ -1,9 +0,0 @@ -const types = require('./dist/types') -const util = require('./dist/util') - -module.exports = types.Schema -module.exports.nullOptions = types.nullOptions -module.exports.strOptions = types.strOptions -module.exports.stringify = util.stringifyString - -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/browser/seq.js b/browser/seq.js deleted file mode 100644 index 66147df3..00000000 --- a/browser/seq.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').YAMLSeq -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/browser/types/binary.js b/browser/types/binary.js deleted file mode 100644 index 271b9de3..00000000 --- a/browser/types/binary.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' -Object.defineProperty(exports, '__esModule', { value: true }) - -const legacy = require('../dist/legacy-exports') -exports.binary = legacy.binary -exports.default = [exports.binary] - -legacy.warnFileDeprecation(__filename) diff --git a/browser/types/omap.js b/browser/types/omap.js deleted file mode 100644 index 37b638b7..00000000 --- a/browser/types/omap.js +++ /dev/null @@ -1,3 +0,0 @@ -const legacy = require('../dist/legacy-exports') -module.exports = legacy.omap -legacy.warnFileDeprecation(__filename) diff --git a/browser/types/pairs.js b/browser/types/pairs.js deleted file mode 100644 index f1df201c..00000000 --- a/browser/types/pairs.js +++ /dev/null @@ -1,3 +0,0 @@ -const legacy = require('../dist/legacy-exports') -module.exports = legacy.pairs -legacy.warnFileDeprecation(__filename) diff --git a/browser/types/set.js b/browser/types/set.js deleted file mode 100644 index e7dc9d42..00000000 --- a/browser/types/set.js +++ /dev/null @@ -1,3 +0,0 @@ -const legacy = require('../dist/legacy-exports') -module.exports = legacy.set -legacy.warnFileDeprecation(__filename) diff --git a/browser/types/timestamp.js b/browser/types/timestamp.js deleted file mode 100644 index 39c5b6dd..00000000 --- a/browser/types/timestamp.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' -Object.defineProperty(exports, '__esModule', { value: true }) - -const legacy = require('../dist/legacy-exports') -exports.default = [legacy.intTime, legacy.floatTime, legacy.timestamp] -exports.floatTime = legacy.floatTime -exports.intTime = legacy.intTime -exports.timestamp = legacy.timestamp - -legacy.warnFileDeprecation(__filename) diff --git a/map.js b/map.js deleted file mode 100644 index 78f2ebc7..00000000 --- a/map.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').YAMLMap -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/pair.js b/pair.js deleted file mode 100644 index b2880a25..00000000 --- a/pair.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').Pair -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/scalar.js b/scalar.js deleted file mode 100644 index deee1b03..00000000 --- a/scalar.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').Scalar -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/schema.js b/schema.js deleted file mode 100644 index 4139c4bf..00000000 --- a/schema.js +++ /dev/null @@ -1,9 +0,0 @@ -const types = require('./dist/types') -const util = require('./dist/util') - -module.exports = types.Schema -module.exports.nullOptions = types.nullOptions -module.exports.strOptions = types.strOptions -module.exports.stringify = util.stringifyString - -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/seq.js b/seq.js deleted file mode 100644 index 66147df3..00000000 --- a/seq.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = require('./dist/types').YAMLSeq -require('./dist/legacy-exports').warnFileDeprecation(__filename) diff --git a/tests/doc/errors.js b/tests/doc/errors.js index 02f3311a..0b3a8046 100644 --- a/tests/doc/errors.js +++ b/tests/doc/errors.js @@ -334,27 +334,4 @@ describe('deprecations', () => { doc.setSchema() expect(mock).toHaveBeenCalledTimes(1) }) - - const files = [ - 'map', - 'pair', - 'scalar', - 'schema', - 'seq', - 'types/binary', - 'types/omap', - 'types/pairs', - 'types/set', - 'types/timestamp' - ] - const root = path.resolve(__dirname, '../..') - const fileTest = fs.existsSync(path.resolve(root, 'dist')) ? test : test.skip - for (const file of files) - fileTest(`file: ${file}`, () => { - const fp = path.resolve(root, file) - // await import() may fail with ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING due - // to https://github.com/facebook/jest/issues/9430 - require(fp) - expect(mock).toHaveBeenCalledTimes(1) - }) }) diff --git a/types/binary.js b/types/binary.js deleted file mode 100644 index 271b9de3..00000000 --- a/types/binary.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' -Object.defineProperty(exports, '__esModule', { value: true }) - -const legacy = require('../dist/legacy-exports') -exports.binary = legacy.binary -exports.default = [exports.binary] - -legacy.warnFileDeprecation(__filename) diff --git a/types/omap.js b/types/omap.js deleted file mode 100644 index 37b638b7..00000000 --- a/types/omap.js +++ /dev/null @@ -1,3 +0,0 @@ -const legacy = require('../dist/legacy-exports') -module.exports = legacy.omap -legacy.warnFileDeprecation(__filename) diff --git a/types/pairs.js b/types/pairs.js deleted file mode 100644 index f1df201c..00000000 --- a/types/pairs.js +++ /dev/null @@ -1,3 +0,0 @@ -const legacy = require('../dist/legacy-exports') -module.exports = legacy.pairs -legacy.warnFileDeprecation(__filename) diff --git a/types/set.js b/types/set.js deleted file mode 100644 index e7dc9d42..00000000 --- a/types/set.js +++ /dev/null @@ -1,3 +0,0 @@ -const legacy = require('../dist/legacy-exports') -module.exports = legacy.set -legacy.warnFileDeprecation(__filename) diff --git a/types/timestamp.js b/types/timestamp.js deleted file mode 100644 index 39c5b6dd..00000000 --- a/types/timestamp.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' -Object.defineProperty(exports, '__esModule', { value: true }) - -const legacy = require('../dist/legacy-exports') -exports.default = [legacy.intTime, legacy.floatTime, legacy.timestamp] -exports.floatTime = legacy.floatTime -exports.intTime = legacy.intTime -exports.timestamp = legacy.timestamp - -legacy.warnFileDeprecation(__filename) From cfdb776b76c36618be41b14e8a95463a976c28f3 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 13:19:24 +0300 Subject: [PATCH 2/9] Drop deprecated "tags" option (use "customTags" instead) --- src/doc/Schema.js | 18 ++---------------- tests/doc/errors.js | 6 ------ 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/doc/Schema.js b/src/doc/Schema.js index cda85e7a..fd970d73 100644 --- a/src/doc/Schema.js +++ b/src/doc/Schema.js @@ -1,7 +1,6 @@ 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' @@ -12,25 +11,12 @@ 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) { diff --git a/tests/doc/errors.js b/tests/doc/errors.js index 0b3a8046..1a468f32 100644 --- a/tests/doc/errors.js +++ b/tests/doc/errors.js @@ -328,10 +328,4 @@ describe('deprecations', () => { cMock.mockRestore() } }) - - test('tags option', () => { - const doc = new YAML.Document({ tags: [] }) - doc.setSchema() - expect(mock).toHaveBeenCalledTimes(1) - }) }) From aa72891708065109ab937c4c0bf7d6f8439b7a96 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 13:43:40 +0300 Subject: [PATCH 3/9] Drop warnFileDeprecation() and warnOptionDeprecation(), refactor & test warn() --- docs/03_options.md | 2 +- src/legacy-exports.js | 2 -- src/warnings.js | 53 +++++++++------------------------------- tests/doc/errors.js | 56 ++++++++++--------------------------------- 4 files changed, 24 insertions(+), 89 deletions(-) diff --git a/docs/03_options.md b/docs/03_options.md index ce76e359..2316aa36 100644 --- a/docs/03_options.md +++ b/docs/03_options.md @@ -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. diff --git a/src/legacy-exports.js b/src/legacy-exports.js index d62d0133..e7d14feb 100644 --- a/src/legacy-exports.js +++ b/src/legacy-exports.js @@ -3,5 +3,3 @@ export { omap } from './tags/yaml-1.1/omap.js' export { pairs } from './tags/yaml-1.1/pairs.js' export { set } from './tags/yaml-1.1/set.js' export { floatTime, intTime, timestamp } from './tags/yaml-1.1/timestamp.js' - -export { warnFileDeprecation } from './warnings' diff --git a/src/warnings.js b/src/warnings.js index 8afa5dcd..95262592 100644 --- a/src/warnings.js +++ b/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) } diff --git a/tests/doc/errors.js b/tests/doc/errors.js index 1a468f32..7c233a56 100644 --- a/tests/doc/errors.js +++ b/tests/doc/errors.js @@ -1,11 +1,5 @@ -import fs from 'fs' -import path from 'path' import { Node } from '../../src/cst/Node.js' import { YAMLError } from '../../src/errors.js' -import { - warnFileDeprecation, - warnOptionDeprecation -} from '../../src/warnings.js' import { YAML } from '../../src/index.js' test('require a message and source for all errors', () => { @@ -278,54 +272,28 @@ test('multiple tags on one node', () => { expect(doc.warnings).toMatchObject([{}]) }) -describe('deprecations', () => { +describe('warnings', () => { let mock beforeEach(() => { mock = jest.spyOn(global.process, 'emitWarning').mockImplementation() }) afterEach(() => mock.mockRestore()) - describe('env vars', () => { - let prevAll, prevDeprecations - beforeEach(() => { - prevAll = global.YAML_SILENCE_WARNINGS - prevDeprecations = global.YAML_SILENCE_DEPRECATION_WARNINGS - }) - afterEach(() => { - global.YAML_SILENCE_WARNINGS = prevAll - global.YAML_SILENCE_DEPRECATION_WARNINGS = prevDeprecations - }) - - test('YAML_SILENCE_WARNINGS', () => { - global.YAML_SILENCE_WARNINGS = true - warnFileDeprecation('foo') - warnOptionDeprecation('bar1', 'baz') - expect(mock).toHaveBeenCalledTimes(0) - }) - - test('YAML_SILENCE_DEPRECATION_WARNINGS', () => { - global.YAML_SILENCE_DEPRECATION_WARNINGS = true - warnFileDeprecation('foo') - warnOptionDeprecation('bar2', 'baz') - expect(mock).toHaveBeenCalledTimes(0) - }) - }) - - test('only warn once', () => { - warnOptionDeprecation('bar3') - warnOptionDeprecation('bar3') - expect(mock).toHaveBeenCalledTimes(1) + test('warn for tag fallback', () => { + YAML.parse('!foo bar') + const message = + 'The tag !foo is unavailable, falling back to tag:yaml.org,2002:str' + expect(mock.mock.calls).toMatchObject([[{ message }, undefined]]) }) - test('without process.emitWarning', () => { - global.process.emitWarning = null - const cMock = jest.spyOn(console, 'warn').mockImplementation() + test('silence with env var', () => { + const prev = global.YAML_SILENCE_WARNINGS try { - warnFileDeprecation('foo') - warnOptionDeprecation('bar4', 'baz') - expect(cMock).toHaveBeenCalledTimes(2) + global.YAML_SILENCE_WARNINGS = true + YAML.parse('!foo bar') + expect(mock).toHaveBeenCalledTimes(0) } finally { - cMock.mockRestore() + global.YAML_SILENCE_WARNINGS = prev } }) }) From acf66469eb7d85e12bd97e2362948200115330b1 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 13:45:46 +0300 Subject: [PATCH 4/9] Drop legacy-exports.js as unused --- rollup.browser-config.js | 1 - rollup.node-config.js | 1 - src/legacy-exports.js | 5 ----- 3 files changed, 7 deletions(-) delete mode 100644 src/legacy-exports.js diff --git a/rollup.browser-config.js b/rollup.browser-config.js index d74f4cb2..3ca2cb62 100644 --- a/rollup.browser-config.js +++ b/rollup.browser-config.js @@ -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' diff --git a/rollup.node-config.js b/rollup.node-config.js index 725e969f..1ab73d96 100644 --- a/rollup.node-config.js +++ b/rollup.node-config.js @@ -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', diff --git a/src/legacy-exports.js b/src/legacy-exports.js deleted file mode 100644 index e7d14feb..00000000 --- a/src/legacy-exports.js +++ /dev/null @@ -1,5 +0,0 @@ -export { binary } from './tags/yaml-1.1/binary.js' -export { omap } from './tags/yaml-1.1/omap.js' -export { pairs } from './tags/yaml-1.1/pairs.js' -export { set } from './tags/yaml-1.1/set.js' -export { floatTime, intTime, timestamp } from './tags/yaml-1.1/timestamp.js' From 27ea12c184d17a83a4e1a82b0d878cd0a8b10ffd Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 14:05:12 +0300 Subject: [PATCH 5/9] Drop Schema.defaultPrefix & Schema.defaultTags; use constants instead --- src/doc/Document.js | 3 ++- src/doc/Schema.js | 10 +--------- src/doc/createNode.js | 5 +++-- types.d.ts | 10 ---------- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/doc/Document.js b/src/doc/Document.js index bd00be79..92fc65cf 100644 --- a/src/doc/Document.js +++ b/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' @@ -152,7 +153,7 @@ export class Document { listNonDefaultTags() { return listTagNames(this.contents).filter( - t => t.indexOf(Schema.defaultPrefix) !== 0 + t => t.indexOf(defaultTagPrefix) !== 0 ) } diff --git a/src/doc/Schema.js b/src/doc/Schema.js index fd970d73..c2a7ecd4 100644 --- a/src/doc/Schema.js +++ b/src/doc/Schema.js @@ -1,5 +1,4 @@ import { Pair } from '../ast/Pair.js' -import { defaultTagPrefix, defaultTags } from '../constants.js' import { schemas, tags } from '../tags/index.js' import { createNode } from './createNode.js' import { getSchemaTags } from './getSchemaTags.js' @@ -8,9 +7,6 @@ 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 }) { this.merge = !!merge this.name = schema @@ -20,11 +16,7 @@ export class 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) } diff --git a/src/doc/createNode.js b/src/doc/createNode.js index e4f5c3b1..c3f8405c 100644 --- a/src/doc/createNode.js +++ b/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' @@ -23,9 +24,9 @@ function findTagObject(value, tagName, tags) { 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) { diff --git a/types.d.ts b/types.d.ts index 411e74e8..07c83327 100644 --- a/types.d.ts +++ b/types.d.ts @@ -9,16 +9,6 @@ export const nullOptions: scalarOptions.Null export const strOptions: scalarOptions.Str export class Schema { - /** Default: `'tag:yaml.org,2002:'` */ - static defaultPrefix: string - static defaultTags: { - /** Default: `'tag:yaml.org,2002:map'` */ - MAP: string - /** Default: `'tag:yaml.org,2002:seq'` */ - SEQ: string - /** Default: `'tag:yaml.org,2002:str'` */ - STR: string - } constructor(options: Schema.Options) /** * Convert any value into a `Node` using this schema, recursively turning From aa8d1a6f0776a523c250fe68b703b8cd67e54d33 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 14:08:56 +0300 Subject: [PATCH 6/9] Drop support for custom tags using "class" instead of "identify" --- src/doc/createNode.js | 9 +-------- src/stringify/stringify.js | 6 +----- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/doc/createNode.js b/src/doc/createNode.js index c3f8405c..fac627b9 100644 --- a/src/doc/createNode.js +++ b/src/doc/createNode.js @@ -12,14 +12,7 @@ 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) { diff --git a/src/stringify/stringify.js b/src/stringify/stringify.js index de0a2305..5ac1a7e8 100644 --- a/src/stringify/stringify.js +++ b/src/stringify/stringify.js @@ -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 { From b41dae61fcc50c14658b41d22b8962be4ca05975 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 14:24:57 +0300 Subject: [PATCH 7/9] Default to pretty errors --- playground | 2 +- src/options.js | 2 +- tests/doc/YAML-1.2.spec.js | 5 ++++- tests/doc/errors.js | 9 +++++++++ tests/doc/parse.js | 2 +- tests/doc/types.js | 5 ++++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/playground b/playground index 2cc02a08..e6e37865 160000 --- a/playground +++ b/playground @@ -1 +1 @@ -Subproject commit 2cc02a08046e89375aac6bc0c8db270f2dc87cbd +Subproject commit e6e378652a365ba961d05971c1e25cbf85d9d207 diff --git a/src/options.js b/src/options.js index c6780504..c0a662b4 100644 --- a/src/options.js +++ b/src/options.js @@ -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' } diff --git a/tests/doc/YAML-1.2.spec.js b/tests/doc/YAML-1.2.spec.js index 1bc83901..94377c6c 100644 --- a/tests/doc/YAML-1.2.spec.js +++ b/tests/doc/YAML-1.2.spec.js @@ -1833,7 +1833,7 @@ matches %: 20`, } } -let origFoldOptions +let origFoldOptions, origPrettyErrors beforeAll(() => { origFoldOptions = YAML.scalarOptions.str.fold @@ -1841,10 +1841,13 @@ beforeAll(() => { 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) { diff --git a/tests/doc/errors.js b/tests/doc/errors.js index 7c233a56..d8ec4d51 100644 --- a/tests/doc/errors.js +++ b/tests/doc/errors.js @@ -2,6 +2,15 @@ import { Node } from '../../src/cst/Node.js' import { YAMLError } from '../../src/errors.js' import { YAML } from '../../src/index.js' +let origPrettyErrors +beforeAll(() => { + origPrettyErrors = YAML.defaultOptions.prettyErrors + YAML.defaultOptions.prettyErrors = false +}) +afterAll(() => { + YAML.defaultOptions.prettyErrors = origPrettyErrors +}) + test('require a message and source for all errors', () => { const exp = /Invalid arguments/ expect(() => new YAMLError()).toThrow(exp) diff --git a/tests/doc/parse.js b/tests/doc/parse.js index b81676b7..3e10b9ff 100644 --- a/tests/doc/parse.js +++ b/tests/doc/parse.js @@ -576,7 +576,7 @@ describe('handling complex keys', () => { }) test('add warning to doc when casting key in collection to string', () => { - const doc = YAML.parseDocument('[foo]: bar') + const doc = YAML.parseDocument('[foo]: bar', { prettyErrors: false }) const message = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.' expect(doc.warnings).toMatchObject([{ message }]) diff --git a/tests/doc/types.js b/tests/doc/types.js index 20ff67c5..cd360647 100644 --- a/tests/doc/types.js +++ b/tests/doc/types.js @@ -4,7 +4,7 @@ import { binary } from '../../src/tags/yaml-1.1/binary.js' import { YAMLOMap } from '../../src/tags/yaml-1.1/omap.js' import { YAMLSet } from '../../src/tags/yaml-1.1/set.js' -let origFoldOptions +let origFoldOptions, origPrettyErrors beforeAll(() => { origFoldOptions = YAML.scalarOptions.str.fold @@ -12,10 +12,13 @@ beforeAll(() => { lineWidth: 20, minContentWidth: 0 } + origPrettyErrors = YAML.defaultOptions.prettyErrors + YAML.defaultOptions.prettyErrors = false }) afterAll(() => { YAML.scalarOptions.str.fold = origFoldOptions + YAML.defaultOptions.prettyErrors = origPrettyErrors }) describe('json schema', () => { From 24471ab47fd4bcdd826f8dc0bba2f94d8d02f5bd Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 14:30:12 +0300 Subject: [PATCH 8/9] Drop "./": "./" from package.json exports; add "./package.json" --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a0b4bd33..4cb1eeda 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ }, "exports": { ".": "./index.js", + "./package.json": "./package.json", "./parse-cst": "./parse-cst.js", "./types": [ { @@ -54,8 +55,7 @@ "import": "./util.mjs" }, "./util.js" - ], - "./": "./" + ] }, "scripts": { "build": "npm run build:node && npm run build:browser", From dc1ac547b65ba7a33cb76a73ed997a49bc3bb867 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 16 May 2020 14:35:35 +0300 Subject: [PATCH 9/9] Specify version as 2.0.0-alpha in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4cb1eeda..e341c568 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yaml", - "version": "1.10.0", + "version": "2.0.0-alpha", "license": "ISC", "author": "Eemeli Aro ", "repository": "github:eemeli/yaml",