@atlaspack/utils 3.0.4-dev-yarn-8750a7d2e.0 → 3.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaspack/utils
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#852](https://github.com/atlassian-labs/atlaspack/pull/852) [`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a) Thanks [@marcins](https://github.com/marcins)! - Support passing a function for source property in schema validation to allow for deferred reads of files
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`02f6aa1`](https://github.com/atlassian-labs/atlaspack/commit/02f6aa1906953fc184d2b49c905c2ef815cb878d), [`58527ee`](https://github.com/atlassian-labs/atlaspack/commit/58527eec15c1aebaaadbeb63586f3082c16beae3), [`525898e`](https://github.com/atlassian-labs/atlaspack/commit/525898e33cc229a4bc938ae853732be36d20c01a), [`cfb39a0`](https://github.com/atlassian-labs/atlaspack/commit/cfb39a0d729eb620cf2ca1611750a2bf7a080d08), [`d0c7bea`](https://github.com/atlassian-labs/atlaspack/commit/d0c7bea04458255b4c5d4299600e734b5f919fe1), [`1086c6a`](https://github.com/atlassian-labs/atlaspack/commit/1086c6a2c59271b63b3fb78e6acdb9d3a0dbf354), [`9cd9521`](https://github.com/atlassian-labs/atlaspack/commit/9cd9521978f783046e2ae4ce78f2de7aeb07d073), [`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
12
+ - @atlaspack/rust@3.9.0
13
+ - @atlaspack/feature-flags@2.26.0
14
+ - @atlaspack/logger@2.14.28
15
+ - @atlaspack/types-internal@2.20.6
16
+ - @atlaspack/codeframe@2.13.18
17
+
3
18
  ## 3.0.3
4
19
 
5
20
  ### Patch Changes
package/dist/config.js CHANGED
@@ -13,8 +13,8 @@ const path_1 = __importDefault(require("path"));
13
13
  const clone_1 = __importDefault(require("clone"));
14
14
  const json5_1 = __importDefault(require("json5"));
15
15
  const toml_1 = require("@iarna/toml");
16
- // @ts-expect-error TS7016
17
16
  const lru_cache_1 = __importDefault(require("lru-cache"));
17
+ // @ts-expect-error TS2351
18
18
  const configCache = new lru_cache_1.default({ max: 500 });
19
19
  const resolveCache = new Map();
20
20
  function resolveConfig(fs, filepath, filenames, projectRoot) {
package/dist/schema.js CHANGED
@@ -280,18 +280,30 @@ function fuzzySearch(expectedValues, actualValue) {
280
280
  return result.map(([v]) => v);
281
281
  }
282
282
  validateSchema.diagnostic = function (schema, data, origin, message) {
283
- if ('source' in data &&
284
- 'data' in data &&
285
- typeof data.source !== 'string' &&
286
- !data) {
287
- throw new Error('At least one of data.source and data.data must be defined!');
283
+ if (!('map' in data) && !('source' in data || 'data' in data)) {
284
+ throw new Error('At least one of data.source, data.data, or data.map must be defined!');
285
+ }
286
+ let loadedSource;
287
+ function loadSource(loader) {
288
+ if (loadedSource !== undefined) {
289
+ return loadedSource;
290
+ }
291
+ else if (typeof loader === 'function') {
292
+ loadedSource = loader();
293
+ return loadedSource;
294
+ }
295
+ else if (typeof loader === 'string') {
296
+ loadedSource = loader;
297
+ return loadedSource;
298
+ }
299
+ return loadedSource;
288
300
  }
289
301
  // @ts-expect-error TS2339
290
302
  let object = data.map
291
303
  ? // @ts-expect-error TS2339
292
304
  data.map.data
293
305
  : // @ts-expect-error TS2339
294
- (data.data ?? JSON.parse(data.source));
306
+ (data.data ?? JSON.parse(loadSource(data.source)));
295
307
  let errors = validateSchema(schema, object);
296
308
  if (errors.length) {
297
309
  let keys = errors.map((e) => {
@@ -358,11 +370,13 @@ validateSchema.diagnostic = function (schema, data, origin, message) {
358
370
  if (data.map) {
359
371
  // @ts-expect-error TS2339
360
372
  map = data.map;
361
- code = data.source;
373
+ code = loadSource(data.source);
362
374
  }
363
375
  else {
364
- // @ts-expect-error TS2339
365
- map = data.source ?? JSON.stringify((0, nullthrows_1.default)(data.data), 0, '\t');
376
+ map =
377
+ loadSource(data.source) ??
378
+ // @ts-expect-error TS2339
379
+ JSON.stringify((0, nullthrows_1.default)(data.data), 0, '\t');
366
380
  code = map;
367
381
  }
368
382
  let codeFrames = [
package/lib/config.js CHANGED
@@ -52,8 +52,7 @@ function _lruCache() {
52
52
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
53
  // @ts-expect-error TS7016
54
54
 
55
- // @ts-expect-error TS7016
56
-
55
+ // @ts-expect-error TS2351
57
56
  const configCache = new (_lruCache().default)({
58
57
  max: 500
59
58
  });
package/lib/schema.js CHANGED
@@ -252,15 +252,28 @@ function fuzzySearch(expectedValues, actualValue) {
252
252
  return result.map(([v]) => v);
253
253
  }
254
254
  validateSchema.diagnostic = function (schema, data, origin, message) {
255
- if ('source' in data && 'data' in data && typeof data.source !== 'string' && !data) {
256
- throw new Error('At least one of data.source and data.data must be defined!');
255
+ if (!('map' in data) && !('source' in data || 'data' in data)) {
256
+ throw new Error('At least one of data.source, data.data, or data.map must be defined!');
257
+ }
258
+ let loadedSource;
259
+ function loadSource(loader) {
260
+ if (loadedSource !== undefined) {
261
+ return loadedSource;
262
+ } else if (typeof loader === 'function') {
263
+ loadedSource = loader();
264
+ return loadedSource;
265
+ } else if (typeof loader === 'string') {
266
+ loadedSource = loader;
267
+ return loadedSource;
268
+ }
269
+ return loadedSource;
257
270
  }
258
271
  // @ts-expect-error TS2339
259
272
  let object = data.map ?
260
273
  // @ts-expect-error TS2339
261
274
  data.map.data :
262
275
  // @ts-expect-error TS2339
263
- data.data ?? JSON.parse(data.source);
276
+ data.data ?? JSON.parse(loadSource(data.source));
264
277
  let errors = validateSchema(schema, object);
265
278
  if (errors.length) {
266
279
  let keys = errors.map(e => {
@@ -323,10 +336,11 @@ validateSchema.diagnostic = function (schema, data, origin, message) {
323
336
  if (data.map) {
324
337
  // @ts-expect-error TS2339
325
338
  map = data.map;
326
- code = data.source;
339
+ code = loadSource(data.source);
327
340
  } else {
341
+ map = loadSource(data.source) ??
328
342
  // @ts-expect-error TS2339
329
- map = data.source ?? JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
343
+ JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
330
344
  code = map;
331
345
  }
332
346
  let codeFrames = [{
@@ -88,10 +88,10 @@ export type SchemaError = {
88
88
  declare function validateSchema(schema: SchemaEntity, data: unknown): Array<SchemaError>;
89
89
  declare namespace validateSchema {
90
90
  var diagnostic: (schema: SchemaEntity, data: ({
91
- source?: string | null | undefined;
91
+ source?: (() => string) | string | null | undefined;
92
92
  data?: unknown;
93
93
  } | {
94
- source: string;
94
+ source: string | (() => string);
95
95
  map: {
96
96
  data: unknown;
97
97
  pointers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/utils",
3
- "version": "3.0.4-dev-yarn-8750a7d2e.0",
3
+ "version": "3.1.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -31,19 +31,20 @@
31
31
  }
32
32
  },
33
33
  "dependencies": {
34
- "@atlaspack/codeframe": "2.13.18-dev-yarn-8750a7d2e.0",
35
- "@atlaspack/diagnostic": "2.14.5-dev-yarn-8750a7d2e.0",
36
- "@atlaspack/feature-flags": "2.25.6-dev-yarn-8750a7d2e.0",
37
- "@atlaspack/logger": "2.14.28-dev-yarn-8750a7d2e.0",
38
- "@atlaspack/markdown-ansi": "2.14.5-dev-yarn-8750a7d2e.0",
39
- "@atlaspack/rust": "3.8.4-dev-yarn-8750a7d2e.0",
40
- "@atlaspack/types-internal": "2.20.6-dev-yarn-8750a7d2e.0",
41
- "@iarna/toml": "^2.2.3",
34
+ "@atlaspack/codeframe": "2.13.18",
35
+ "@atlaspack/diagnostic": "2.14.4",
36
+ "@atlaspack/feature-flags": "2.26.0",
37
+ "@atlaspack/logger": "2.14.28",
38
+ "@atlaspack/markdown-ansi": "2.14.4",
39
+ "@atlaspack/types-internal": "2.20.6",
40
+ "@atlaspack/rust": "3.9.0",
42
41
  "@parcel/source-map": "^2.1.1",
43
42
  "@types/micromatch": "^4.0.9",
44
43
  "@types/node-forge": "^1.3.13",
45
- "ansi-html-community": "0.0.8",
46
44
  "chalk": "^4.1.0",
45
+ "nullthrows": "^1.1.1",
46
+ "@iarna/toml": "^2.2.0",
47
+ "ansi-html-community": "0.0.8",
47
48
  "clone": "^2.1.1",
48
49
  "fast-glob": "^3.2.12",
49
50
  "fastest-levenshtein": "^1.0.16",
@@ -53,14 +54,13 @@
53
54
  "lru-cache": "^6.0.0",
54
55
  "micromatch": "^4.0.4",
55
56
  "node-forge": "^1.2.1",
56
- "nullthrows": "^1.1.1",
57
57
  "open": "^7.0.3",
58
58
  "snarkdown": "^2.0.0",
59
59
  "strip-ansi": "^6.0.0",
60
60
  "terminal-link": "^2.1.1"
61
61
  },
62
62
  "devDependencies": {
63
- "@atlaspack/babel-register": "2.14.5-dev-yarn-8750a7d2e.0",
63
+ "@atlaspack/babel-register": "2.14.4",
64
64
  "@types/is-glob": "^4.0.1",
65
65
  "benny": "^3.7.1",
66
66
  "random-int": "^1.0.0"
@@ -74,6 +74,5 @@
74
74
  "type": "commonjs",
75
75
  "scripts": {
76
76
  "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
77
- },
78
- "gitHead": "8750a7d2e6330244dd618c28a20d5a391080e4a3"
77
+ }
79
78
  }
package/src/config.ts CHANGED
@@ -6,7 +6,6 @@ import path from 'path';
6
6
  import clone from 'clone';
7
7
  import json5 from 'json5';
8
8
  import {parse as toml} from '@iarna/toml';
9
- // @ts-expect-error TS7016
10
9
  import LRU from 'lru-cache';
11
10
 
12
11
  export type ConfigOutput = {
@@ -19,6 +18,7 @@ export type ConfigOptions = {
19
18
  parser?: (arg1: string) => any;
20
19
  };
21
20
 
21
+ // @ts-expect-error TS2351
22
22
  const configCache = new LRU<FilePath, ConfigOutput>({max: 500});
23
23
  const resolveCache = new Map();
24
24
 
package/src/schema.ts CHANGED
@@ -391,11 +391,11 @@ validateSchema.diagnostic = function (
391
391
  schema: SchemaEntity,
392
392
  data: (
393
393
  | {
394
- source?: string | null | undefined;
394
+ source?: (() => string) | string | null | undefined;
395
395
  data?: unknown;
396
396
  }
397
397
  | {
398
- source: string;
398
+ source: string | (() => string);
399
399
  map: {
400
400
  data: unknown;
401
401
  pointers: {
@@ -410,22 +410,32 @@ validateSchema.diagnostic = function (
410
410
  origin: string,
411
411
  message: string,
412
412
  ): undefined {
413
- if (
414
- 'source' in data &&
415
- 'data' in data &&
416
- typeof data.source !== 'string' &&
417
- !data
418
- ) {
413
+ if (!('map' in data) && !('source' in data || 'data' in data)) {
419
414
  throw new Error(
420
- 'At least one of data.source and data.data must be defined!',
415
+ 'At least one of data.source, data.data, or data.map must be defined!',
421
416
  );
422
417
  }
418
+ let loadedSource: string | null | undefined;
419
+ function loadSource(
420
+ loader: string | (() => string) | null | undefined,
421
+ ): string | null | undefined {
422
+ if (loadedSource !== undefined) {
423
+ return loadedSource;
424
+ } else if (typeof loader === 'function') {
425
+ loadedSource = loader();
426
+ return loadedSource;
427
+ } else if (typeof loader === 'string') {
428
+ loadedSource = loader;
429
+ return loadedSource;
430
+ }
431
+ return loadedSource;
432
+ }
423
433
  // @ts-expect-error TS2339
424
434
  let object = data.map
425
435
  ? // @ts-expect-error TS2339
426
436
  data.map.data
427
437
  : // @ts-expect-error TS2339
428
- (data.data ?? JSON.parse(data.source));
438
+ (data.data ?? JSON.parse(loadSource(data.source)));
429
439
  let errors = validateSchema(schema, object);
430
440
  if (errors.length) {
431
441
  let keys = errors.map((e) => {
@@ -487,10 +497,12 @@ validateSchema.diagnostic = function (
487
497
  if (data.map) {
488
498
  // @ts-expect-error TS2339
489
499
  map = data.map;
490
- code = data.source;
500
+ code = loadSource(data.source);
491
501
  } else {
492
- // @ts-expect-error TS2339
493
- map = data.source ?? JSON.stringify(nullthrows(data.data), 0, '\t');
502
+ map =
503
+ loadSource(data.source) ??
504
+ // @ts-expect-error TS2339
505
+ JSON.stringify(nullthrows(data.data), 0, '\t');
494
506
  code = map;
495
507
  }
496
508
  let codeFrames = [