@unvt/charites 2.1.1 → 2.1.3

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.
@@ -38,6 +38,14 @@ export async function serve(source, options) {
38
38
  }
39
39
  const server = http.createServer(async (req, res) => {
40
40
  const url = (req.url || '').replace(/\?.*/, '');
41
+ res.setHeader('Access-Control-Allow-Origin', '*');
42
+ res.setHeader('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS');
43
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
44
+ if (req.method === 'OPTIONS') {
45
+ res.statusCode = 204;
46
+ res.end();
47
+ return;
48
+ }
41
49
  if (typeof spriteOut !== 'undefined' &&
42
50
  url.match(/^\/sprite(@2x)?\.(json|png)/)) {
43
51
  res.statusCode = 200;
@@ -1,9 +1,8 @@
1
- import axios from 'axios';
2
1
  import { BaseImporter } from './base-importer.js';
3
2
  export class MetadataJSONImporter extends BaseImporter {
4
3
  async getJSON(url) {
5
- const res = await axios.get(url);
6
- const matadataJSON = res.data;
4
+ const res = await fetch(url);
5
+ const matadataJSON = await res.json();
7
6
  const metadataName = matadataJSON.name
8
7
  ? matadataJSON.name
9
8
  : Math.random().toString(32).substring(2);
@@ -1,9 +1,8 @@
1
- import axios from 'axios';
2
1
  import { BaseImporter } from './base-importer.js';
3
2
  export class TileJSONImporter extends BaseImporter {
4
3
  async getJSON(url) {
5
- const res = await axios.get(url);
6
- const tilejson = res.data;
4
+ const res = await fetch(url);
5
+ const tilejson = await res.json();
7
6
  const tilesetName = tilejson.name
8
7
  ? tilejson.name
9
8
  : Math.random().toString(32).substring(2);
@@ -1,23 +1,19 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import yaml from 'js-yaml';
3
+ import YAML from 'yaml';
4
4
  import * as yamlinc from './index.js';
5
- function construct(data) {
6
- const basepath = yamlinc.getBasePath();
7
- const fullpath = path.join(basepath, data);
8
- yamlinc.YAML_VISITED_FILES.push(fullpath.replace(basepath + path.sep, ''));
9
- const src = fs.readFileSync(fullpath, 'utf8');
10
- const included = yaml.load(src, {
11
- schema: yamlinc.YAML_INCLUDE_SCHEMA,
12
- filename: fullpath,
13
- });
14
- return included;
15
- }
16
- function resolve(data) {
17
- return typeof data === 'string';
18
- }
19
- export default new yaml.Type('tag:yaml.org,2002:inc/file', {
20
- kind: 'scalar',
21
- resolve: resolve,
22
- construct: construct,
23
- });
5
+ const fileTag = {
6
+ identify: () => false,
7
+ tag: 'tag:yaml.org,2002:inc/file',
8
+ resolve(str) {
9
+ const basepath = yamlinc.getBasePath();
10
+ const fullpath = path.join(basepath, str);
11
+ yamlinc.YAML_VISITED_FILES.push(fullpath.replace(basepath + path.sep, ''));
12
+ const src = fs.readFileSync(fullpath, 'utf8');
13
+ const included = YAML.parse(src, {
14
+ customTags: yamlinc.YAML_TYPES,
15
+ });
16
+ return included;
17
+ },
18
+ };
19
+ export default fileTag;
@@ -1,4 +1,3 @@
1
- import yaml from 'js-yaml';
2
1
  import path from 'path';
3
2
  // import YamlIncludeDirType from './lib/dir';
4
3
  import YamlIncludeFileType from './file.js';
@@ -7,7 +6,7 @@ export const YAML_TYPES = [
7
6
  // YamlIncludeDirType,
8
7
  YamlIncludeFileType,
9
8
  ];
10
- export const YAML_INCLUDE_SCHEMA = yaml.DEFAULT_SCHEMA.extend(YAML_TYPES);
9
+ export const YAML_INCLUDE_SCHEMA = { customTags: YAML_TYPES };
11
10
  export let basefile = '';
12
11
  // so we know where to find files referenced relative to the base file
13
12
  export function setBaseFile(file) {
@@ -1,14 +1,12 @@
1
1
  import fs from 'fs';
2
- import YAML from 'js-yaml';
2
+ import YAML from 'yaml';
3
3
  import * as yamlinc from './yaml-include/index.js';
4
4
  export function parser(file) {
5
5
  yamlinc.setBaseFile(file);
6
6
  const schema = yamlinc.YAML_INCLUDE_SCHEMA;
7
7
  const yaml = fs.readFileSync(file, 'utf8');
8
- const obj = YAML.load(yaml, {
9
- schema,
10
- filename: file,
11
- json: true,
8
+ const obj = YAML.parse(yaml, {
9
+ ...schema,
12
10
  });
13
11
  const styleObj = {};
14
12
  const variables = {};
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
- import YAML from 'js-yaml';
3
+ import YAML from 'yaml';
4
4
  export const writeYaml = (destinationPath, style, composite = false) => {
5
5
  if (composite === true) {
6
6
  writeCompositedYaml(destinationPath, style);
@@ -10,7 +10,11 @@ export const writeYaml = (destinationPath, style, composite = false) => {
10
10
  }
11
11
  };
12
12
  const writeCompositedYaml = (destinationPath, style) => {
13
- const styleYAML = YAML.dump(style);
13
+ const styleYAML = YAML.stringify(style, null, {
14
+ singleQuote: true,
15
+ indent: 2,
16
+ lineWidth: 40,
17
+ });
14
18
  let stylePath = path.resolve(process.cwd(), destinationPath);
15
19
  // The `source` is absolute path.
16
20
  if (destinationPath.match(/^\//)) {
@@ -24,23 +28,31 @@ class IncFileTag {
24
28
  // We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
25
29
  this.value = path.posix.join('layers', fileName);
26
30
  }
31
+ toString() {
32
+ return this.value;
33
+ }
27
34
  }
28
- const INC_PATH_TYPE = new YAML.Type('tag:yaml.org,2002:inc/file', {
29
- kind: 'scalar',
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- resolve: (data) => data,
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- construct: (data) => new IncFileTag(data),
34
- instanceOf: IncFileTag,
35
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- represent: (tag) => tag.value,
37
- });
38
- const INC_PATH_OUTPUT_SCHEMA = YAML.DEFAULT_SCHEMA.extend([INC_PATH_TYPE]);
35
+ export const INC_PATH_TYPE = {
36
+ tag: 'tag:yaml.org,2002:inc/file',
37
+ identify: (value) => value instanceof IncFileTag,
38
+ resolve: (str) => str,
39
+ stringify: (item) => {
40
+ if (item instanceof IncFileTag) {
41
+ const value = item.value;
42
+ return value;
43
+ }
44
+ return String(item);
45
+ },
46
+ };
39
47
  const writeDecompositedYaml = (destinationPath, style) => {
40
48
  const layers = [];
41
49
  for (let i = 0; i < style.layers.length; i++) {
42
50
  const layer = style.layers[i];
43
- const layerYml = YAML.dump(layer);
51
+ const layerYml = YAML.stringify(layer, null, {
52
+ singleQuote: true,
53
+ indent: 2,
54
+ lineWidth: 40,
55
+ });
44
56
  const fileName = `${style.layers[i].id}.yml`;
45
57
  const layersDirName = path.join(path.dirname(destinationPath), 'layers');
46
58
  const filePath = path.join(layersDirName, fileName);
@@ -51,7 +63,11 @@ const writeDecompositedYaml = (destinationPath, style) => {
51
63
  layers.push(new IncFileTag(fileName));
52
64
  }
53
65
  style.layers = layers;
54
- fs.writeFileSync(destinationPath, YAML.dump(style, {
55
- schema: INC_PATH_OUTPUT_SCHEMA,
56
- }));
66
+ const yamlOutput = YAML.stringify(style, null, {
67
+ customTags: [INC_PATH_TYPE],
68
+ singleQuote: true,
69
+ indent: 2,
70
+ lineWidth: 40,
71
+ });
72
+ fs.writeFileSync(destinationPath, yamlOutput);
57
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unvt/charites",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "charites": "dist/cli.js"
@@ -21,45 +21,43 @@
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "@maplibre/maplibre-gl-inspect": "^1.7.1",
24
- "@maplibre/maplibre-gl-style-spec": "^23.2.2",
24
+ "@maplibre/maplibre-gl-style-spec": "^23.3.0",
25
25
  "@unvt/sprite-one": "^0.1.1",
26
26
  "@watergis/maplibre-gl-legend": "^2.0.5",
27
- "axios": "^1.9.0",
28
- "commander": "^13.1.0",
27
+ "commander": "^14.0.0",
29
28
  "glob": "^11.0.2",
30
- "js-yaml": "^4.1.0",
31
29
  "jsonminify": "^0.4.2",
32
- "maplibre-gl": "^5.4.0",
30
+ "maplibre-gl": "^5.5.0",
33
31
  "node-watch": "^0.7.4",
34
32
  "open": "^10.1.2",
35
33
  "pmtiles": "^4.3.0",
36
- "vite": "^6.3.4",
37
- "ws": "^8.18.2"
34
+ "vite": "^6.3.5",
35
+ "ws": "^8.18.2",
36
+ "yaml": "^2.8.0"
38
37
  },
39
38
  "devDependencies": {
40
39
  "@eslint/eslintrc": "^3.3.1",
41
- "@eslint/js": "^9.26.0",
40
+ "@eslint/js": "^9.27.0",
42
41
  "@playwright/test": "^1.52.0",
43
- "@types/chai": "^5.2.1",
42
+ "@types/chai": "^5.2.2",
44
43
  "@types/chai-as-promised": "^8.0.2",
45
44
  "@types/fs-extra": "^11.0.4",
46
45
  "@types/geojson": "^7946.0.16",
47
- "@types/js-yaml": "^4.0.9",
48
46
  "@types/jsonminify": "^0.4.3",
49
47
  "@types/mapbox__point-geometry": "^0.1.4",
50
48
  "@types/mocha": "^10.0.10",
51
- "@types/node": "^22.15.3",
49
+ "@types/node": "^22.15.19",
52
50
  "@types/ws": "^8.18.1",
53
- "@typescript-eslint/eslint-plugin": "^8.31.1",
54
- "@typescript-eslint/parser": "^8.31.1",
51
+ "@typescript-eslint/eslint-plugin": "^8.32.1",
52
+ "@typescript-eslint/parser": "^8.32.1",
55
53
  "chai": "^5.2.0",
56
54
  "chai-as-promised": "^8.0.1",
57
- "eslint": "^9.26.0",
58
- "eslint-config-prettier": "^10.1.2",
59
- "eslint-plugin-prettier": "^5.2.6",
55
+ "eslint": "^9.27.0",
56
+ "eslint-config-prettier": "^10.1.5",
57
+ "eslint-plugin-prettier": "^5.4.0",
60
58
  "fs-extra": "^11.3.0",
61
59
  "kill-port-process": "^3.2.1",
62
- "mocha": "^11.2.2",
60
+ "mocha": "^11.4.0",
63
61
  "node-abort-controller": "^3.1.1",
64
62
  "prettier": "^3.5.3",
65
63
  "ts-node": "^10.9.2",
@@ -54,6 +54,14 @@ export async function serve(source: string, options: serveOptions) {
54
54
 
55
55
  const server = http.createServer(async (req, res) => {
56
56
  const url = (req.url || '').replace(/\?.*/, '')
57
+ res.setHeader('Access-Control-Allow-Origin', '*')
58
+ res.setHeader('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS')
59
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
60
+ if (req.method === 'OPTIONS') {
61
+ res.statusCode = 204
62
+ res.end()
63
+ return
64
+ }
57
65
 
58
66
  if (
59
67
  typeof spriteOut !== 'undefined' &&
@@ -1,4 +1,3 @@
1
- import axios from 'axios'
2
1
  import { MetadataJSON, VectorLayer } from '../../types/index.js'
3
2
  import {
4
3
  LayerSpecification,
@@ -8,8 +7,8 @@ import { BaseImporter, TileInfoJSONResponse } from './base-importer.js'
8
7
 
9
8
  export class MetadataJSONImporter extends BaseImporter {
10
9
  async getJSON(url: string): Promise<TileInfoJSONResponse> {
11
- const res = await axios.get(url)
12
- const matadataJSON: MetadataJSON = res.data
10
+ const res = await fetch(url)
11
+ const matadataJSON: MetadataJSON = await res.json()
13
12
  const metadataName: string = matadataJSON.name
14
13
  ? matadataJSON.name
15
14
  : Math.random().toString(32).substring(2)
@@ -1,4 +1,3 @@
1
- import axios from 'axios'
2
1
  import { TileJSON } from '../../types/index.js'
3
2
  import {
4
3
  SourceSpecification,
@@ -8,8 +7,8 @@ import { BaseImporter, TileInfoJSONResponse } from './base-importer.js'
8
7
 
9
8
  export class TileJSONImporter extends BaseImporter {
10
9
  async getJSON(url: string): Promise<TileInfoJSONResponse> {
11
- const res = await axios.get(url)
12
- const tilejson: TileJSON = res.data
10
+ const res = await fetch(url)
11
+ const tilejson: TileJSON = await res.json()
13
12
  const tilesetName: string = tilejson.name
14
13
  ? tilejson.name
15
14
  : Math.random().toString(32).substring(2)
@@ -1,29 +1,24 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
- import yaml from 'js-yaml'
3
+ import YAML from 'yaml'
4
4
  import * as yamlinc from './index.js'
5
5
 
6
- function construct(data: string): unknown {
7
- const basepath = yamlinc.getBasePath()
8
- const fullpath = path.join(basepath, data)
6
+ const fileTag = {
7
+ identify: () => false,
8
+ tag: 'tag:yaml.org,2002:inc/file',
9
+ resolve(str: string) {
10
+ const basepath = yamlinc.getBasePath()
11
+ const fullpath = path.join(basepath, str)
9
12
 
10
- yamlinc.YAML_VISITED_FILES.push(fullpath.replace(basepath + path.sep, ''))
13
+ yamlinc.YAML_VISITED_FILES.push(fullpath.replace(basepath + path.sep, ''))
11
14
 
12
- const src = fs.readFileSync(fullpath, 'utf8')
13
- const included = yaml.load(src, {
14
- schema: yamlinc.YAML_INCLUDE_SCHEMA,
15
- filename: fullpath,
16
- })
15
+ const src = fs.readFileSync(fullpath, 'utf8')
16
+ const included = YAML.parse(src, {
17
+ customTags: yamlinc.YAML_TYPES,
18
+ })
17
19
 
18
- return included
20
+ return included
21
+ },
19
22
  }
20
23
 
21
- function resolve(data: unknown): boolean {
22
- return typeof data === 'string'
23
- }
24
-
25
- export default new yaml.Type('tag:yaml.org,2002:inc/file', {
26
- kind: 'scalar',
27
- resolve: resolve,
28
- construct: construct,
29
- })
24
+ export default fileTag
@@ -1,4 +1,3 @@
1
- import yaml from 'js-yaml'
2
1
  import path from 'path'
3
2
 
4
3
  // import YamlIncludeDirType from './lib/dir';
@@ -9,7 +8,7 @@ export const YAML_TYPES = [
9
8
  // YamlIncludeDirType,
10
9
  YamlIncludeFileType,
11
10
  ]
12
- export const YAML_INCLUDE_SCHEMA = yaml.DEFAULT_SCHEMA.extend(YAML_TYPES)
11
+ export const YAML_INCLUDE_SCHEMA = { customTags: YAML_TYPES }
13
12
  export let basefile = ''
14
13
 
15
14
  // so we know where to find files referenced relative to the base file
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs'
2
- import YAML from 'js-yaml'
2
+ import YAML from 'yaml'
3
3
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
4
4
  import * as yamlinc from './yaml-include/index.js'
5
5
 
@@ -12,10 +12,8 @@ export function parser(file: string): StyleSpecification {
12
12
  const schema = yamlinc.YAML_INCLUDE_SCHEMA
13
13
  const yaml = fs.readFileSync(file, 'utf8')
14
14
 
15
- const obj: StyleObject = YAML.load(yaml, {
16
- schema,
17
- filename: file,
18
- json: true,
15
+ const obj: StyleObject = YAML.parse(yaml, {
16
+ ...schema,
19
17
  }) as StyleObject
20
18
 
21
19
  const styleObj: StyleObject = {}
@@ -1,6 +1,6 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
- import YAML from 'js-yaml'
3
+ import YAML from 'yaml'
4
4
  import {
5
5
  StyleSpecification,
6
6
  LayerSpecification,
@@ -22,7 +22,11 @@ const writeCompositedYaml = (
22
22
  destinationPath: string,
23
23
  style: StyleSpecification,
24
24
  ) => {
25
- const styleYAML = YAML.dump(style)
25
+ const styleYAML = YAML.stringify(style, null, {
26
+ singleQuote: true,
27
+ indent: 2,
28
+ lineWidth: 40,
29
+ })
26
30
  let stylePath = path.resolve(process.cwd(), destinationPath)
27
31
 
28
32
  // The `source` is absolute path.
@@ -39,19 +43,24 @@ class IncFileTag {
39
43
  // We use path.posix.join to make sure the path uses / path separators, even when run on Windows.
40
44
  this.value = path.posix.join('layers', fileName)
41
45
  }
46
+
47
+ toString() {
48
+ return this.value
49
+ }
42
50
  }
43
51
 
44
- const INC_PATH_TYPE = new YAML.Type('tag:yaml.org,2002:inc/file', {
45
- kind: 'scalar',
46
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
- resolve: (data: any) => data,
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
- construct: (data: any) => new IncFileTag(data),
50
- instanceOf: IncFileTag,
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- represent: (tag: any) => (tag as IncFileTag).value,
53
- })
54
- const INC_PATH_OUTPUT_SCHEMA = YAML.DEFAULT_SCHEMA.extend([INC_PATH_TYPE])
52
+ export const INC_PATH_TYPE = {
53
+ tag: 'tag:yaml.org,2002:inc/file',
54
+ identify: (value: unknown) => value instanceof IncFileTag,
55
+ resolve: (str: string) => str,
56
+ stringify: (item: IncFileTag | unknown) => {
57
+ if (item instanceof IncFileTag) {
58
+ const value = item.value
59
+ return value
60
+ }
61
+ return String(item)
62
+ },
63
+ }
55
64
 
56
65
  const writeDecompositedYaml = (
57
66
  destinationPath: string,
@@ -61,7 +70,11 @@ const writeDecompositedYaml = (
61
70
 
62
71
  for (let i = 0; i < style.layers.length; i++) {
63
72
  const layer = style.layers[i]
64
- const layerYml = YAML.dump(layer)
73
+ const layerYml = YAML.stringify(layer, null, {
74
+ singleQuote: true,
75
+ indent: 2,
76
+ lineWidth: 40,
77
+ })
65
78
  const fileName = `${style.layers[i].id}.yml`
66
79
  const layersDirName = path.join(path.dirname(destinationPath), 'layers')
67
80
  const filePath = path.join(layersDirName, fileName)
@@ -75,10 +88,12 @@ const writeDecompositedYaml = (
75
88
 
76
89
  style.layers = layers
77
90
 
78
- fs.writeFileSync(
79
- destinationPath,
80
- YAML.dump(style, {
81
- schema: INC_PATH_OUTPUT_SCHEMA,
82
- }),
83
- )
91
+ const yamlOutput = YAML.stringify(style, null, {
92
+ customTags: [INC_PATH_TYPE],
93
+ singleQuote: true,
94
+ indent: 2,
95
+ lineWidth: 40,
96
+ })
97
+
98
+ fs.writeFileSync(destinationPath, yamlOutput)
84
99
  }
@@ -91,14 +91,12 @@ describe('Test for the `charites build`', () => {
91
91
  `${charites} build style.yml style.json --sprite-output noExistDirname`,
92
92
  tmpdir,
93
93
  )
94
- promise.should.be.rejected
95
- .then(function () {
96
- return assert.isRejected(
97
- promise,
98
- /noExistDirname: No such directory. Please specify valid icon output directory. For more help run charites build --help\n/,
99
- )
100
- })
101
- .should.notify(done)
94
+ assert
95
+ .isRejected(
96
+ promise,
97
+ /noExistDirname: No such directory. Please specify valid icon output directory. For more help run charites build --help\n/,
98
+ )
99
+ .then(() => done(), done)
102
100
  })
103
101
 
104
102
  it('charites build print error message', () => {
@@ -1,6 +1,5 @@
1
1
  import { expect } from 'chai'
2
2
  import { AbortController } from 'node-abort-controller'
3
- import axios from 'axios'
4
3
  import { abortableExecFile } from './util/execPromise'
5
4
  import { copyFixturesDir, copyFixturesFile } from './util/copyFixtures'
6
5
  import { makeTempDir } from './util/makeTempDir'
@@ -29,13 +28,13 @@ describe('Test for `charites serve`', () => {
29
28
  await sleep(500)
30
29
  await Promise.all([
31
30
  (async () => {
32
- const res = await axios('http://127.0.0.1:8080/style.json', {})
33
- expect(res.data.version).to.equal(8)
31
+ const res = await fetch('http://127.0.0.1:8080/style.json')
32
+ const data = await res.json()
33
+ expect(data.version).to.equal(8)
34
34
  })(),
35
35
  (async () => {
36
- await axios('http://127.0.0.1:8080/sprite.json', {
37
- validateStatus: (status) => status === 404,
38
- })
36
+ const res = await fetch('http://127.0.0.1:8080/sprite.json')
37
+ expect(res.status).to.equal(404)
39
38
  })(),
40
39
  ])
41
40
  } finally {
@@ -67,30 +66,35 @@ describe('Test for `charites serve`', () => {
67
66
  await sleep(500)
68
67
  await Promise.all([
69
68
  (async () => {
70
- const res = await axios('http://127.0.0.1:8080/style.json', {})
69
+ const res = await fetch('http://127.0.0.1:8080/style.json')
71
70
  expect(res.status).to.equal(200)
72
- expect(res.data.version).to.equal(8)
73
- expect(res.data.sprite).to.equal('http://127.0.0.1:8080/sprite')
71
+ const data = await res.json()
72
+ expect(data.version).to.equal(8)
73
+ expect(data.sprite).to.equal('http://127.0.0.1:8080/sprite')
74
74
  })(),
75
75
  (async () => {
76
- const res = await axios('http://127.0.0.1:8080/sprite.json', {})
76
+ const res = await fetch('http://127.0.0.1:8080/sprite.json')
77
77
  expect(res.status).to.equal(200)
78
- expect(Object.entries(res.data).length).to.be.greaterThan(0)
78
+ const data = await res.json()
79
+ expect(Object.entries(data).length).to.be.greaterThan(0)
79
80
  })(),
80
81
  (async () => {
81
- const res = await axios('http://127.0.0.1:8080/sprite@2x.json', {})
82
+ const res = await fetch('http://127.0.0.1:8080/sprite@2x.json')
82
83
  expect(res.status).to.equal(200)
83
- expect(Object.entries(res.data).length).to.be.greaterThan(0)
84
+ const data = await res.json()
85
+ expect(Object.entries(data).length).to.be.greaterThan(0)
84
86
  })(),
85
87
  (async () => {
86
- const res = await axios('http://127.0.0.1:8080/sprite.png', {})
88
+ const res = await fetch('http://127.0.0.1:8080/sprite.png')
87
89
  expect(res.status).to.equal(200)
88
- expect(res.data.length).to.be.greaterThan(0)
90
+ const buffer = await res.arrayBuffer()
91
+ expect(buffer.byteLength).to.be.greaterThan(0)
89
92
  })(),
90
93
  (async () => {
91
- const res = await axios('http://127.0.0.1:8080/sprite@2x.png', {})
94
+ const res = await fetch('http://127.0.0.1:8080/sprite@2x.png')
92
95
  expect(res.status).to.equal(200)
93
- expect(res.data.length).to.be.greaterThan(0)
96
+ const buffer = await res.arrayBuffer()
97
+ expect(buffer.byteLength).to.be.greaterThan(0)
94
98
  })(),
95
99
  ])
96
100
  } finally {
@@ -9,6 +9,9 @@ import { build } from '../src/commands/build'
9
9
  import { fileURLToPath } from 'url'
10
10
  import { dirname } from 'path'
11
11
 
12
+ import YAML from 'yaml'
13
+ import { INC_PATH_TYPE } from '../src/lib/yaml-writer'
14
+
12
15
  const __filename = fileURLToPath(import.meta.url)
13
16
  const __dirname = dirname(__filename)
14
17
 
@@ -31,8 +34,10 @@ describe('Test for the `convert.ts`.', () => {
31
34
  convert(jsonPath, yamlPath)
32
35
  const yml = fs.readFileSync(yamlPath, 'utf-8')
33
36
 
34
- assert.equal(
35
- `version: 8
37
+ assert.deepEqual(
38
+ YAML.parse(yml, { customTags: [INC_PATH_TYPE] }),
39
+ YAML.parse(
40
+ `version: 8
36
41
  name: example
37
42
  metadata: {}
38
43
  sources:
@@ -47,7 +52,8 @@ layers:
47
52
  layers/background-with-very-long-name-background-with-very-long-name-background-with-very-long-name.yml
48
53
  id: example
49
54
  `,
50
- yml,
55
+ { customTags: [INC_PATH_TYPE] },
56
+ ),
51
57
  )
52
58
 
53
59
  const outJsonPath = path.join(tmp, 'converted-back.json')
package/test/init.spec.ts CHANGED
@@ -2,12 +2,13 @@ import { assert } from 'chai'
2
2
  import path from 'path'
3
3
  import fs from 'fs'
4
4
  import os from 'os'
5
- import YAML from 'js-yaml'
5
+ import YAML from 'yaml'
6
6
 
7
7
  import { init, initOptions } from '../src/commands/init'
8
8
 
9
9
  import { fileURLToPath } from 'url'
10
10
  import { dirname } from 'path'
11
+ import { INC_PATH_TYPE } from '../src/lib/yaml-writer'
11
12
  const __filename = fileURLToPath(import.meta.url)
12
13
  const __dirname = dirname(__filename)
13
14
 
@@ -23,8 +24,8 @@ describe('Test for the `init.ts`.', () => {
23
24
  assert.deepEqual(true, !!fs.statSync(styleYaml))
24
25
  // the file should be the same with init.yml
25
26
  assert.deepEqual(
26
- YAML.load(fs.readFileSync(styleYaml, 'utf8')),
27
- YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
27
+ YAML.parse(fs.readFileSync(styleYaml, 'utf8')),
28
+ YAML.parse(fs.readFileSync(tempStylePath, 'utf-8')),
28
29
  )
29
30
  })
30
31
 
@@ -45,36 +46,11 @@ describe('Test for the `init.ts`.', () => {
45
46
  assert.deepEqual(true, !!fs.statSync(styleYaml))
46
47
  // the file should be the same with init_tilejson.yml
47
48
  assert.deepEqual(
48
- YAML.load(fs.readFileSync(styleYaml, 'utf8')),
49
- YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
49
+ YAML.parse(fs.readFileSync(styleYaml, 'utf8')),
50
+ YAML.parse(fs.readFileSync(tempStylePath, 'utf-8')),
50
51
  )
51
52
  })
52
53
 
53
- /*
54
- it('Should produce composited style.yml without layers if tilejson without vector_layers is specified', async () => {
55
- const tempStylePath = path.join(
56
- __dirname,
57
- 'data/init/init_tilejson_without_layers.yml',
58
- )
59
- const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
60
- const styleYaml = path.join(tmpdir, 'style.yml')
61
-
62
- const options: initOptions = {
63
- tilejsonUrls: 'https://a.tiles.mapbox.com/v3/aj.1x1-degrees.json',
64
- compositeLayers: true,
65
- }
66
-
67
- await init(styleYaml, options)
68
-
69
- // The file should exists.
70
- assert.deepEqual(true, !!fs.statSync(styleYaml))
71
- assert.deepEqual(
72
- YAML.load(fs.readFileSync(styleYaml, 'utf8')),
73
- YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
74
- )
75
- })
76
- */
77
-
78
54
  it('Should initialize default decomposited style.yml from tilejson provided', async () => {
79
55
  const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'charites-'))
80
56
  const styleYaml = path.join(tmpdir, 'style.yml')
@@ -91,22 +67,25 @@ describe('Test for the `init.ts`.', () => {
91
67
  assert.deepEqual(true, !!fs.statSync(styleYaml))
92
68
  // the file should be the same with init_tilejson.yml
93
69
  assert.deepEqual(
94
- fs.readFileSync(styleYaml, 'utf8').replace(/\r\n/gm, '\n'),
95
- fs
96
- .readFileSync(
70
+ YAML.parse(fs.readFileSync(styleYaml, 'utf8'), {
71
+ customTags: [INC_PATH_TYPE],
72
+ }),
73
+ YAML.parse(
74
+ fs.readFileSync(
97
75
  path.join(__dirname, 'data/init/tilejson/init_decomposite.yml'),
98
76
  'utf-8',
99
- )
100
- .replace(/\r\n/gm, '\n'),
77
+ ),
78
+ { customTags: [INC_PATH_TYPE] },
79
+ ),
101
80
  )
102
81
  assert.deepEqual(
103
- YAML.load(
82
+ YAML.parse(
104
83
  fs.readFileSync(
105
84
  path.join(tmpdir, 'layers/bicycle_parking.yml'),
106
85
  'utf8',
107
86
  ),
108
87
  ),
109
- YAML.load(
88
+ YAML.parse(
110
89
  fs.readFileSync(
111
90
  path.join(__dirname, 'data/init/tilejson/layers/bicycle_parking.yml'),
112
91
  'utf-8',
@@ -114,10 +93,10 @@ describe('Test for the `init.ts`.', () => {
114
93
  ),
115
94
  )
116
95
  assert.deepEqual(
117
- YAML.load(
96
+ YAML.parse(
118
97
  fs.readFileSync(path.join(tmpdir, 'layers/showers.yml'), 'utf8'),
119
98
  ),
120
- YAML.load(
99
+ YAML.parse(
121
100
  fs.readFileSync(
122
101
  path.join(__dirname, 'data/init/tilejson/layers/showers.yml'),
123
102
  'utf-8',
@@ -125,10 +104,10 @@ describe('Test for the `init.ts`.', () => {
125
104
  ),
126
105
  )
127
106
  assert.deepEqual(
128
- YAML.load(
107
+ YAML.parse(
129
108
  fs.readFileSync(path.join(tmpdir, 'layers/telephone.yml'), 'utf8'),
130
109
  ),
131
- YAML.load(
110
+ YAML.parse(
132
111
  fs.readFileSync(
133
112
  path.join(__dirname, 'data/init/tilejson/layers/telephone.yml'),
134
113
  'utf-8',
@@ -153,8 +132,8 @@ describe('Test for the `init.ts`.', () => {
153
132
  // The file should exists.
154
133
  assert.deepEqual(true, !!fs.statSync(styleYaml))
155
134
  assert.deepEqual(
156
- YAML.load(fs.readFileSync(styleYaml, 'utf8')),
157
- YAML.load(fs.readFileSync(tempStylePath, 'utf-8')),
135
+ YAML.parse(fs.readFileSync(styleYaml, 'utf8')),
136
+ YAML.parse(fs.readFileSync(tempStylePath, 'utf-8')),
158
137
  )
159
138
  })
160
139
  })