// loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import fileSystem from 'node:fs'; import path from 'node:path'; import {expect, test} from 'vitest'; const REPOSITORY_ROOT = process.cwd(); const MODULE_NAMES = ['archives', 'core', 'ogc', 'tiles', 'tiles-3d']; const ENTRYPOINT_NAME = /(?:loader|writer|source)(?:-types)?$/; test.each( MODULE_NAMES )('%s exposes named loader, writer, and source entrypoints at package level', moduleName => { const moduleDirectory = path.join(REPOSITORY_ROOT, 'modules', moduleName); const manifest = JSON.parse( fileSystem.readFileSync(path.join(moduleDirectory, 'package.json'), 'utf8') ); const exports = manifest.exports as Record>; const nestedEntrypoints = Object.keys(exports).filter(exportPath => { if (!exportPath.startsWith('./')) return false; const segments = exportPath.slice(2).split('/'); return segments.length === 2 && ENTRYPOINT_NAME.test(segments[1]); }); expect(nestedEntrypoints, moduleName).toEqual([]); const flatEntrypoints = Object.entries(exports).filter(([exportPath]) => { if (!exportPath.startsWith('./')) return false; const segments = exportPath.slice(2).split('/'); return segments.length === 1 && ENTRYPOINT_NAME.test(segments[0]); }); expect(flatEntrypoints.length, moduleName).toBeGreaterThan(0); for (const [exportPath, conditions] of flatEntrypoints) { const entrypointName = exportPath.slice(2); const targets = typeof conditions === 'string' ? [conditions] : Object.values(conditions); for (const target of targets) { expect( fileSystem.existsSync(path.join(moduleDirectory, target)), moduleName + exportPath + ': ' + target ).toBe(true); } if (typeof conditions !== 'string') { expect(conditions.types, moduleName + exportPath).toBe(`./dist/${entrypointName}.d.ts`); expect(conditions.import, moduleName + exportPath).toBe(`./dist/${entrypointName}.js`); if (conditions.require) { expect(conditions.require, moduleName + exportPath).toBe(`./dist/${entrypointName}.cjs`); } } } }); // Format packages expose one API entrypoint and a bundled parser variant per format. test.each([ 'geospatial', 'pointclouds', 'raster', 'scene', 'tables', 'documents', 'scientific', 'images' ])('%s exposes formats instead of individual descriptors', moduleName => { const directory = path.join(REPOSITORY_ROOT, 'modules', moduleName); const manifest = JSON.parse( fileSystem.readFileSync(path.join(directory, 'package.json'), 'utf8') ); const entries = Object.entries(manifest.exports) as [string, string | Record][]; expect( entries.filter(([name]) => /^\.\/[^/]+-(loader|writer|source)(-types)?$/.test(name)) ).toEqual([]); const bundled = entries.filter(([name]) => name.endsWith('/bundled')); expect(bundled.length).toBeGreaterThan(0); for (const [name, conditions] of bundled) { expect(manifest.exports).toHaveProperty(name.slice(0, -'/bundled'.length)); for (const target of typeof conditions === 'string' ? [conditions] : Object.values(conditions)) { expect( fileSystem.existsSync(path.join(directory, target)), `${moduleName}${name}: ${target}` ).toBe(true); } } });