Comparing version 0.2.2 to 0.3.0
@@ -63,2 +63,12 @@ const { inspect } = require('util') | ||
/** | ||
* A reference to the children for this entity' node. | ||
* @public | ||
* @accessor | ||
* @type {Array} | ||
*/ | ||
get children() { | ||
return this.node.children | ||
} | ||
/** | ||
* A reference to the attributes for this entity' node. | ||
@@ -106,3 +116,3 @@ * @public | ||
function filter(key, descriptors) { | ||
if (['constructor', 'document', 'attributes', 'text', 'node'].includes(key)) { | ||
if (['constructor', 'document', 'children', 'attributes', 'text', 'node'].includes(key)) { | ||
return false | ||
@@ -109,0 +119,0 @@ } |
@@ -6,4 +6,2 @@ const { createReadStream } = require('./stream') | ||
const debug = require('debug')('mediaxml') | ||
const path = require('path') | ||
const fs = require('fs') | ||
@@ -14,9 +12,2 @@ function createLoader(context, opts) { | ||
const { cache = new Map() } = opts | ||
const state = { | ||
paths: [], | ||
get cwd() { | ||
const i = Math.max(0, this.paths.length - 1) | ||
return this.paths[i] || process.cwd() | ||
} | ||
} | ||
@@ -29,6 +20,5 @@ return async function load(uri) { | ||
let stream = null | ||
let cwd = state.cwd | ||
const { imports } = context | ||
const cacheKey = hash([cwd, uri]) | ||
const cacheKey = hash(uri) | ||
const buffers = [] | ||
@@ -42,2 +32,3 @@ | ||
cache.set(cacheKey, promise) | ||
return promise | ||
@@ -47,3 +38,3 @@ | ||
try { | ||
stream = await createReadStream(uri, { cwd }) | ||
stream = await createReadStream(uri) | ||
} catch (err) { | ||
@@ -55,19 +46,4 @@ debug(err) | ||
try { | ||
void new URL(uri) // this should fail for regular file paths | ||
} catch (err) { | ||
try { | ||
fs.accessSync(uri, fs.constants.R_OK | fs.constants.F_OK) | ||
state.paths.push(path.resolve(path.dirname(uri))) | ||
} catch (err) { | ||
debug(err) | ||
return reject(err) | ||
} | ||
} | ||
cwd = state.cwd | ||
context.imports.cwd = cwd | ||
if ('function' === typeof opts.onbeforeload) { | ||
opts.onbeforeload({ uri, cwd, imports }) | ||
opts.onbeforeload({ uri, imports }) | ||
} | ||
@@ -81,3 +57,3 @@ | ||
if ('function' === typeof opts.onerror) { | ||
opts.onerror(err, { uri, cwd, imports }) | ||
opts.onerror(err, { uri, imports }) | ||
} | ||
@@ -90,3 +66,3 @@ | ||
if ('function' === typeof opts.ondata) { | ||
opts.ondata(buffer, { uri, cwd, imports }) | ||
opts.ondata(buffer, { uri, imports }) | ||
} | ||
@@ -115,9 +91,6 @@ | ||
} | ||
} finally { | ||
state.paths.pop() | ||
context.imports.cwd = state.cwd | ||
} | ||
if ('function' === typeof opts.onload) { | ||
opts.onload(result, { uri, cwd, imports }) | ||
opts.onload(result, { uri, imports }) | ||
} | ||
@@ -124,0 +97,0 @@ |
{ | ||
"name": "mediaxml", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "A general purpose module for working with XML that includes first class support for media manifests like ADI, mRSS, and SCTE-236.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -386,4 +386,2 @@ const { normalizeValue } = require('../normalize') | ||
--imports.queued | ||
if ('string' === typeof name) { | ||
@@ -411,3 +409,3 @@ try { | ||
if (!resolved) { | ||
debug('import lock released: name could not be resolved', name) | ||
debug('import lock released: name could not be resolved %s in %s', name, cwd) | ||
promise.reject(new Error(`Could not resolve import: "${name}"`)) | ||
@@ -461,2 +459,7 @@ return release() | ||
lock((release) => { | ||
--imports.queued | ||
release() | ||
}) | ||
return promise | ||
@@ -463,0 +466,0 @@ } |
@@ -16,3 +16,3 @@ const REGEX = /((?!\s$).*)\s*?contains\b\s*((['|"].*['|"])|([0-9|a-z|A-Z|$|_|.]+))/g | ||
if (/[[]$/.test(normalizedPrefix)) { | ||
if (/([[]|or|and)$/.test(normalizedPrefix)) { | ||
output.push('$ ~>') | ||
@@ -19,0 +19,0 @@ } else { |
@@ -14,2 +14,3 @@ const { clearScreenDown, moveCursor } = require('readline') | ||
const timer = Timer.now('query') | ||
const cwd = process.cwd() | ||
let result = null | ||
@@ -32,3 +33,3 @@ | ||
try { | ||
result = await parser.query(query, { imports, assignments }) | ||
result = await parser.query(query, { cwd, imports, assignments }) | ||
@@ -35,0 +36,0 @@ const output = pretty(result) |
@@ -7,2 +7,3 @@ const { clearScreenDown, cursorTo, moveCursor } = require('readline') | ||
const { createLoader } = require('../loader') | ||
const { validate } = require('../validate') | ||
const { Parser } = require('../parser') | ||
@@ -205,4 +206,3 @@ const { pretty } = require('./pretty') | ||
if (parser.rootNode) { | ||
this.parser.nodes[0] = parser.rootNode | ||
this.parser.end() | ||
this.parser = parser | ||
} else { | ||
@@ -329,3 +329,3 @@ parser.promise | ||
if (query) { | ||
if (query && query.trim().length > 3) { | ||
// double wildcards can be expensive | ||
@@ -341,2 +341,7 @@ if ('**' === query.trim()) { | ||
// don't try to preview imports and lets | ||
if (/^\s*?(import|let)\s*?.*$/.test(query.trim())) { | ||
return | ||
} | ||
try { | ||
@@ -403,3 +408,6 @@ result = await parser.query(query, { imports, assignments }) | ||
process.stdin.setRawMode(true) | ||
if ('function' === typeof process.stdin.setRawMode) { | ||
process.stdin.setRawMode(true) | ||
} | ||
process.stdin.on('error', this.onerror) | ||
@@ -439,2 +447,6 @@ process.stdin.on('keypress', this.onkeypress) | ||
function createContext(filename, opts) { | ||
if (Buffer.isBuffer(filename)) { | ||
filename = String(filename) | ||
} | ||
if (filename && 'object' === typeof filename && !filename.pipe) { | ||
@@ -448,5 +460,17 @@ opts = filename | ||
if (filename && !opts.parser) { | ||
if ('string' === typeof filename || filename.pipe) { | ||
opts.parser = Parser.from(createReadStream(filename)) | ||
if ('string' === typeof filename) { | ||
try { | ||
const tmp = String(filename) | ||
validate(tmp) | ||
opts.parser = Parser.from(tmp) | ||
} catch (err) { | ||
debug(err) | ||
} | ||
} | ||
if (!opts.parser) { | ||
if ('string' === typeof filename || filename.pipe) { | ||
opts.parser = Parser.from(createReadStream(filename)) | ||
} | ||
} | ||
} | ||
@@ -453,0 +477,0 @@ |
@@ -30,3 +30,3 @@ const { format } = require('util') | ||
info() { | ||
info(...args) { | ||
if (false !== this.context.options.colors) { | ||
@@ -33,0 +33,0 @@ console.info(' %s:', chalk.blue('info'), format(...args)) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2524173
14238
11