Skip to content

Commit c18f12f

Browse files
authored
Merge pull request #59 from colinhacks/test-single-bin
Add simple `"bin"` test
2 parents a4beb97 + 876b102 commit c18f12f

File tree

15 files changed

+167
-5
lines changed

15 files changed

+167
-5
lines changed

.github/workflows/publish-latest.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
name: Publish --latest
22

33
on:
4+
workflow_dispatch: # allow manual trigger for testing
45
push:
56
paths:
67
- 'VERSION.txt'
78
branches:
89
- main
910

10-
# Allow manual trigger for testing
11-
workflow_dispatch:
12-
1311
jobs:
1412
publish:
1513
name: Main

src/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ Examples:
227227
if (typeof rawConfig.exports === "string") {
228228
rawConfig.exports = { ".": rawConfig.exports };
229229
} else if (typeof rawConfig.exports === "undefined") {
230-
log.error(`❌ Missing "exports" key in package.json#/${CONFIG_KEY}`);
231-
process.exit(1);
230+
// exports is optional if bin is specified
231+
if (!rawConfig.bin) {
232+
log.error(`❌ Missing "exports" key in package.json#/${CONFIG_KEY}`);
233+
process.exit(1);
234+
}
232235
} else if (typeof rawConfig.exports !== "object") {
233236
log.error(`❌ Invalid "exports" key in package.json#/${CONFIG_KEY}`);
234237
process.exit(1);

test/__snapshots__/zshy.test.ts.snap

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,93 @@ exports[`zshy with different tsconfig configurations > should skip CJS build whe
327327
}
328328
`;
329329
330+
exports[`zshy with different tsconfig configurations > should support bin without exports (should not overwrite existing exports) 1`] = `
331+
{
332+
"exitCode": 0,
333+
"stderr": "",
334+
"stdout": "╔═══════════════════════════════════════════════
335+
zshy » the bundler-free TypeScript build tool
336+
╚═══════════════════════════════════════════════╝
337+
» Starting build...
338+
» Verbose mode enabled
339+
» Detected package manager: <pm>
340+
» Build will fail only on errors (default)
341+
» Detected project root: <root>/test/bin
342+
» Reading package.json from ./package.json
343+
» Parsed zshy config: {
344+
"bin": "./src/cli.ts"
345+
}
346+
» Reading tsconfig from ./tsconfig.json
347+
» Determining entrypoints...
348+
╔══════════════════╤══════════════╗
349+
║ Subpath │ Entrypoint ║
350+
╟──────────────────┼──────────────╢
351+
║ bin:bin-only-pkg │ ./src/cli.ts ║
352+
╚══════════════════╧══════════════╝
353+
» Resolved build paths:
354+
╔══════════╤═══════════════╗
355+
║ Location │ Resolved path ║
356+
╟──────────┼───────────────╢
357+
║ rootDir │ ./src ║
358+
║ outDir │ ./dist ║
359+
╚══════════╧═══════════════╝
360+
» Package is an ES module (package.json#/type is "module")
361+
» Cleaning up outDir...
362+
» Cleaning up declarationDir...
363+
» Resolved entrypoints: [
364+
"./src/cli.ts"
365+
]
366+
» Resolved compilerOptions: {
367+
"lib": [
368+
"lib.esnext.d.ts"
369+
],
370+
"target": "ES2020",
371+
"module": "ESNext",
372+
"moduleResolution": "Bundler",
373+
"moduleDetection": 2,
374+
"allowJs": true,
375+
"declaration": true,
376+
"jsx": 4,
377+
"allowImportingTsExtensions": true,
378+
"rewriteRelativeImportExtensions": true,
379+
"verbatimModuleSyntax": false,
380+
"noEmit": false,
381+
"strict": true,
382+
"skipLibCheck": true,
383+
"noFallthroughCasesInSwitch": true,
384+
"noUncheckedIndexedAccess": true,
385+
"esModuleInterop": true,
386+
"forceConsistentCasingInFileNames": true,
387+
"noUnusedLocals": true,
388+
"noUnusedParameters": false,
389+
"noPropertyAccessFromIndexSignature": false,
390+
"sourceMap": true,
391+
"declarationMap": true,
392+
"resolveJsonModule": true,
393+
"noImplicitOverride": true,
394+
"noImplicitThis": true,
395+
"outDir": "<root>/test/bin/dist",
396+
"emitDeclarationOnly": false,
397+
"composite": false
398+
}
399+
» Building CJS... (rewriting .ts -> .cjs/.d.cts)
400+
» Enabling CJS interop transform...
401+
» Building ESM...
402+
» Writing files (8 total)...
403+
./dist/cli.cjs
404+
./dist/cli.cjs.map
405+
./dist/cli.d.cts
406+
./dist/cli.d.cts.map
407+
./dist/cli.d.ts
408+
./dist/cli.d.ts.map
409+
./dist/cli.js
410+
./dist/cli.js.map
411+
» Updating package.json...
412+
» Setting "bin": "./dist/cli.cjs"
413+
» Build complete!",
414+
}
415+
`;
416+
330417
exports[`zshy with different tsconfig configurations > should support multiple bin entries 1`] = `
331418
{
332419
"exitCode": 0,

test/bin/dist/cli.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
console.log("Hello from CLI!");
4+
//# sourceMappingURL=cli.js.map

test/bin/dist/cli.cjs.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/bin/dist/cli.d.cts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
//# sourceMappingURL=cli.d.ts.map

test/bin/dist/cli.d.cts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/bin/dist/cli.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
//# sourceMappingURL=cli.d.ts.map

test/bin/dist/cli.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/bin/dist/cli.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)