Skip to content

Commit 138d645

Browse files
committed
Declare the generated root index as a default export
Assisted-By: GPT-6
1 parent 83c3c79 commit 138d645

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎index.mjs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,13 @@ const generateData = async (version) => {
338338
);
339339
fs.writeFileSync(
340340
path.resolve(__dirname, `output/unicode-${version}/index.d.mts`),
341-
Object.keys(dirMap)
342-
.map((key) => `export const ${key}: string[];`)
343-
.join('\n'),
341+
[
342+
'declare const data: {',
343+
...Object.keys(dirMap).map((key) => `\t${key}: string[];`),
344+
'};',
345+
'export default data;',
346+
'',
347+
].join('\n'),
344348
);
345349
fs.writeFileSync(
346350
path.resolve(__dirname, `output/unicode-${version}/package.json`),

‎tests/tests.mjs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { suite, test } from 'node:test';
2+
import fs from 'node:fs';
23
import './parsers.mjs';
34
import './line-endings.mjs';
45
import resources from '../data/resources.mjs';
@@ -16,6 +17,25 @@ if (!process.env.CI) {
1617
// Format fixtures mock the data reader, so register them after generation.
1718
await import('./parser-formats.mjs');
1819

20+
test('Root declarations match the default runtime export', async (t) => {
21+
for (const version of [oldest, newest]) {
22+
const module = await import(`../output/unicode-${version}/index.mjs`);
23+
t.assert.deepEqual(Object.keys(module), ['default']);
24+
const declaration = fs.readFileSync(
25+
new URL(`../output/unicode-${version}/index.d.mts`, import.meta.url),
26+
'utf8',
27+
);
28+
t.assert.match(declaration, /export\s+default\s+\w+\s*;/);
29+
t.assert.doesNotMatch(declaration, /export\s+const\s/);
30+
for (const property of Object.keys(module.default)) {
31+
t.assert.match(
32+
declaration,
33+
new RegExp(`\\b${property}:\\s*string\\[\\]`),
34+
);
35+
}
36+
}
37+
});
38+
1939
suite(`The generated Unicode ${oldest} js`, () => {
2040
test('General_Category/Modifier_Letter should match the snapshot', async (t) => {
2141
const { default: data } = await import(

0 commit comments

Comments
 (0)