package: ship declarations (dist/types, the "types" condition) and a Node JS entry for 'storebound'; Bun keeps the .ts source. 0.8.5 exported only cli/lib/config.ts, so tsc (next build, vue-tsc, tsc --noEmit) failed on a scaffolded storebound.config.ts and broke a Next app's build; a test type-checks the template against the packed entry under bundler / node16 / nodenext without @types/node. check fails on the template's own placeholders (Example Studio, bare example.com URLs and addresses)
This commit is contained in:
parent
77f141e223
commit
d717ceb4cd
10 changed files with 138 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ import { BASE, capture, jsonOut, project, restore } from './helpers/store-mock';
|
|||
afterEach(restore);
|
||||
|
||||
const NAMED: ShipConfig = { ...BASE, app: { ...BASE.app, name: 'STAR DASH' }, apple: { ...BASE.apple!, name: 'STAR DASH: Stone Age to 2100', primaryLocale: 'en-US' } };
|
||||
const PLAIN: ShipConfig = { ...BASE, app: { ...BASE.app, name: 'STAR DASH', copyright: '2026 Example Brand' }, apple: { ...BASE.apple!, primaryLocale: 'en-US' } };
|
||||
const PLAIN: ShipConfig = { ...BASE, app: { ...BASE.app, name: 'STAR DASH', copyright: '2026 Example Brand', privacyPolicyUrl: 'https://rush.example.com/privacy', supportUrl: 'https://rush.example.com/support', website: 'https://rush.example.com', contactEmail: 'support@rush.example.com' }, apple: { ...BASE.apple!, primaryLocale: 'en-US' } };
|
||||
const sec = (loc: string, name?: string) => `## ${loc}\n\n${name ? `### name\n\`\`\`\n${name}\n\`\`\`\n\n` : ''}### subtitle\n\`\`\`\nSub\n\`\`\`\n\n### promotionalText\n\`\`\`\nPromo\n\`\`\`\n\n### keywords\n\`\`\`\nrun,time\n\`\`\`\n\n### description\n\`\`\`\nText.\n\`\`\`\n\n`;
|
||||
|
||||
describe('apple.name', () => {
|
||||
|
|
|
|||
39
tests/package-types.test.ts
Normal file
39
tests/package-types.test.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// The published package as a project's tsc sees it: `import type { ShipConfig } from 'storebound'` in a scaffolded
|
||||
// storebound.config.ts must type-check with plain TypeScript (next build, vue-tsc, ts-loader, tsc --noEmit), not only
|
||||
// under Bun. 0.8.5 shipped "exports": "./cli/lib/config.ts" and no declarations: a Next app stopped building.
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { buildEntry } from '../tools/build-node';
|
||||
|
||||
const ROOT = join(import.meta.dir, '..');
|
||||
const TSC = join(ROOT, 'node_modules', 'typescript', 'bin', 'tsc');
|
||||
|
||||
describe('package types', () => {
|
||||
test('the scaffolded config type-checks against the package under bundler, node16 and nodenext', () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'sb-pkg-types-'));
|
||||
try {
|
||||
const dist = join(dir, 'dist');
|
||||
buildEntry(dist);
|
||||
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
||||
// what npm ships: package.json, the entry files it names, nothing from the checkout's node_modules
|
||||
const sb = join(dir, 'app', 'node_modules', 'storebound');
|
||||
mkdirSync(sb, { recursive: true });
|
||||
writeFileSync(join(sb, 'package.json'), JSON.stringify(pkg));
|
||||
cpSync(dist, join(sb, 'dist'), { recursive: true });
|
||||
expect(pkg.files).toEqual(expect.arrayContaining(['dist/config.js', 'dist/types']));
|
||||
expect(pkg.exports['.'].types).toBe('./dist/types/lib/config.d.ts');
|
||||
symlinkSync(join(ROOT, 'node_modules', 'typescript'), join(dir, 'app', 'node_modules', 'typescript'));
|
||||
cpSync(join(ROOT, 'templates', 'storebound.config.ts'), join(dir, 'app', 'storebound.config.ts'));
|
||||
// an ES module project (node16 / nodenext read the nearest package.json; Next / Vite use bundler resolution)
|
||||
writeFileSync(join(dir, 'app', 'package.json'), JSON.stringify({ name: 'app', private: true, type: 'module' }));
|
||||
for (const [module, moduleResolution] of [['esnext', 'bundler'], ['node16', 'node16'], ['nodenext', 'nodenext']]) {
|
||||
// no @types/node, skipLibCheck off: the strictest project a config can land in
|
||||
writeFileSync(join(dir, 'app', 'tsconfig.json'), JSON.stringify({ compilerOptions: { strict: true, noEmit: true, target: 'es2022', module, moduleResolution, skipLibCheck: false, types: [] }, include: ['*.ts'] }));
|
||||
const r = Bun.spawnSync(['node', TSC, '-p', '.'], { cwd: join(dir, 'app'), stdout: 'pipe', stderr: 'pipe' });
|
||||
expect(`${moduleResolution}: ${r.stdout.toString()}${r.stderr.toString()}`.trim()).toBe(`${moduleResolution}:`);
|
||||
}
|
||||
} finally { rmSync(dir, { recursive: true, force: true }); }
|
||||
}, 120_000);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue