ata-validator 1.46.0 → 1.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ const { env } = require('./env');
2
3
 
3
4
  // Locate the optional native engine. Resolution order:
4
5
  // 1. ATA_NO_NATIVE set -> null (explicit pure-JS mode)
@@ -36,6 +37,12 @@ function detectMusl() {
36
37
  }
37
38
  }
38
39
 
40
+ // The require of the platform package is of a computed name on purpose. A
41
+ // literal require of each of the seven packages was tried: at most one of
42
+ // them is installed on any machine, and a bundler that bundles the Node
43
+ // entry (esbuild, bun, webpack) fails to resolve the other six and stops.
44
+ // A supply-chain scanner reports a computed require as dynamic loading;
45
+ // this is what it loads, and nothing else is ever required by name here.
39
46
  let warned = false;
40
47
  function checkVersion(binding, source) {
41
48
  if (!binding) return null;
@@ -58,7 +65,7 @@ function checkVersion(binding, source) {
58
65
  }
59
66
 
60
67
  module.exports = function loadNative() {
61
- if (process.env.ATA_NO_NATIVE) return null;
68
+ if (env('ATA_NO_NATIVE')) return null;
62
69
 
63
70
  const isMusl = process.platform === 'linux' ? detectMusl() : false;
64
71
  const candidates = [];
@@ -80,6 +87,8 @@ module.exports = function loadNative() {
80
87
 
81
88
  // Contributors running from a source checkout.
82
89
  try {
90
+ // Not a literal path for the same reason: the file is absent from the
91
+ // published package and a bundler must not try to resolve it.
83
92
  const path = require('path');
84
93
  const binding = checkVersion(
85
94
  require(path.join(__dirname, '..', 'build', 'Release', 'ata.node')),
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ const { compileFunction } = require('./compile-fn');
2
3
 
3
4
  // A schema-directed scanner: it answers the verdict from the JSON text without
4
5
  // building the document. `JSON.parse` is three quarters of the cost of a real
@@ -436,7 +437,7 @@ function finish(built, opts) {
436
437
  let fn;
437
438
  try {
438
439
  // eslint-disable-next-line no-new-func
439
- fn = new Function('_h', '_r', ctx.subSource.join('\n') + '\nreturn function scan(s){\n' + body + '\n}')(ctx.helpers, require('./scan-runtime'));
440
+ fn = compileFunction('_h', '_r', ctx.subSource.join('\n') + '\nreturn function scan(s){\n' + body + '\n}')(ctx.helpers, require('./scan-runtime'));
440
441
  } catch {
441
442
  return null; // a runtime without code generation has no scanner, by design
442
443
  }
@@ -10,6 +10,8 @@ function getNative() {
10
10
  if (_nativeMod === undefined) _nativeMod = require("./native-load")();
11
11
  return _nativeMod;
12
12
  }
13
+ const { env } = require('./env');
14
+ const { compileFunction } = require('./compile-fn');
13
15
  const { normalizeKeywords, schemaUsesKeywords } = require('./keywords');
14
16
  // The code generator (lib/js-compiler and what builds on it: the scanner, the
15
17
  // parse() copy, the ahead-of-time emitters) is registered by the entry that
@@ -207,7 +209,7 @@ function codegenAvailable() {
207
209
  if (_codegen === null) return false;
208
210
  if (_codegenAvailable === null) {
209
211
  try {
210
- _codegenAvailable = new Function('return 1')() === 1;
212
+ _codegenAvailable = compileFunction('return 1')() === 1;
211
213
  } catch {
212
214
  _codegenAvailable = false;
213
215
  }
@@ -880,7 +882,7 @@ class Validator {
880
882
  // Check cache first -- reuse compiled functions for same schema
881
883
  const sm = this._schemaMap.size > 0 ? this._schemaMap : null;
882
884
  const mapKey = compileCacheKey(this._schemaStr, this._schemaMap);
883
- var _forceNapi = this._interpretOnly || (typeof process !== 'undefined' && process.env && process.env.ATA_FORCE_NAPI);
885
+ var _forceNapi = this._interpretOnly || env('ATA_FORCE_NAPI');
884
886
  // Custom formats are JS functions: bypass the compile cache since they can
885
887
  // differ between validators that share the same schema string. An
886
888
  // interpreter-only validator never touches it either way: a function a
@@ -1584,7 +1586,7 @@ class Validator {
1584
1586
  return;
1585
1587
  }
1586
1588
  this._ensureVocabularies();
1587
- if (this._interpretOnly || _codegen === null || (typeof process !== 'undefined' && process.env && process.env.ATA_FORCE_NAPI)) return;
1589
+ if (this._interpretOnly || _codegen === null || env('ATA_FORCE_NAPI')) return;
1588
1590
  _codegen.compileVerdict.call(this);
1589
1591
  }
1590
1592
 
package/lib/version.js CHANGED
@@ -7,4 +7,4 @@
7
7
  //
8
8
  // Kept in lockstep with package.json by `tests/test_version_sync.js`.
9
9
 
10
- module.exports = '1.46.0';
10
+ module.exports = '1.47.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "1.46.0",
3
+ "version": "1.47.0",
4
4
  "description": "JSON Schema validator that compiles to plain JavaScript, still runs where code generation is blocked, and can be compiled away at build time. Passes the full official test suite.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -143,13 +143,13 @@
143
143
  "LICENSE"
144
144
  ],
145
145
  "optionalDependencies": {
146
- "@ata-validator/native-darwin-arm64": "1.46.0",
147
- "@ata-validator/native-darwin-x64": "1.46.0",
148
- "@ata-validator/native-linux-arm64-gnu": "1.46.0",
149
- "@ata-validator/native-linux-arm64-musl": "1.46.0",
150
- "@ata-validator/native-linux-x64-gnu": "1.46.0",
151
- "@ata-validator/native-linux-x64-musl": "1.46.0",
152
- "@ata-validator/native-win32-x64": "1.46.0"
146
+ "@ata-validator/native-darwin-arm64": "1.47.0",
147
+ "@ata-validator/native-darwin-x64": "1.47.0",
148
+ "@ata-validator/native-linux-arm64-gnu": "1.47.0",
149
+ "@ata-validator/native-linux-arm64-musl": "1.47.0",
150
+ "@ata-validator/native-linux-x64-gnu": "1.47.0",
151
+ "@ata-validator/native-linux-x64-musl": "1.47.0",
152
+ "@ata-validator/native-win32-x64": "1.47.0"
153
153
  },
154
154
  "peerDependencies": {
155
155
  "yaml": "^2.0.0"