@temir.ra/create-ts-lib 0.6.0 → 0.6.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.6.1
4
+
5
+ 1. Cleaned up dormant imports.
6
+ 2. Cleaned up / updated minor `README.md` inconsistencies.
7
+ 3. Updated placeholders in `README.md` in the **Asset resolution** section.
8
+ 4. Removed **Asset resolution** section from the generated `README.md`, as the operational passage is given in the template `README.md`.
9
+ 5. Removed **AI Assistant Context** section from the `README.md` files.
10
+ 7. Cleaned up **Publish** section in the `README.md`.
11
+
3
12
  ## 0.6.0
4
13
 
5
14
  1. Updated documentation and configs to TypeScript 6.
package/README.md CHANGED
@@ -5,8 +5,7 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
5
5
  ## Table of Contents
6
6
 
7
7
  1. [Quick Start](#quick-start)
8
- 2. [AI Assistant Context](#ai-assistant-context)
9
- 3. [Documentation](#documentation)
8
+ 2. [Documentation](#documentation)
10
9
  1. [`tsconfig.json` and `tsconfig.build.json`](#tsconfigjson-and-tsconfigbuildjson)
11
10
  2. [`package.json`](#packagejson)
12
11
  3. [Script `scripts/buildinfo.ts`](#script-scriptsbuildinfots)
@@ -22,7 +21,7 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
22
21
  3. [README statement for library consumers](#readme-statement-for-library-consumers)
23
22
  4. [When the library is bundled by the consumer](#when-the-library-is-bundled-by-the-consumer)
24
23
  8. [`src/dev.ts`](#srcdevts)
25
- 4. [DevOps](#devops)
24
+ 3. [DevOps](#devops)
26
25
  1. [Change Management](#change-management)
27
26
  2. [Publish](#publish)
28
27
  1. [npmjs.org](#npmjsorg)
@@ -54,12 +53,6 @@ cd <NEW_PACKAGE>
54
53
  bun install
55
54
  ```
56
55
 
57
- # AI Assistant Context
58
-
59
- To generate an AI coding assistant context file for this project:
60
-
61
- > Generate an AI coding assistant context file. Analyze the project structure and source files, using this README as the primary reference for architecture and conventions. Give particular attention to: the dual tsconfig setup and the import constraints it imposes, the `#src/*.js` alias and where it may and may not be used, the custom `entrypoint` export condition, and the asset resolution contract.
62
-
63
56
  # Documentation
64
57
 
65
58
  The following sections explain the configurations and conventions baked into the generated package. Useful when adapting the generated package to fit a specific library's needs.
@@ -78,6 +71,7 @@ See the typescriptlang documentation on [tsconfig.json](https://www.typescriptla
78
71
  "target": "ESNext",
79
72
 
80
73
  // output module format; ESNext passes ES module syntax through unchanged
74
+ // ES module syntax: import/export statements (as opposed to CommonJS require()/module.exports)
81
75
  "module": "ESNext",
82
76
 
83
77
  // type definitions for built-in APIs
@@ -252,7 +246,7 @@ See npmjs documentation on [package.json](https://docs.npmjs.com/cli/v11/configu
252
246
  "scripts": {
253
247
 
254
248
  "clean:dist": "rm -rf dist/",
255
- "clean:tsbuildinfo": "rm -f tsconfig.build.tsbuildinfo",
249
+ "clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
256
250
  "clean": "bun run clean:dist && bun run clean:tsbuildinfo",
257
251
 
258
252
  // lifecycle hook; runs automatically before "build"; generates buildinfo.txt
@@ -266,8 +260,6 @@ See npmjs documentation on [package.json](https://docs.npmjs.com/cli/v11/configu
266
260
  // bundles the library into ESM and IIFE formats for distribution
267
261
  "build:lib-bundle": "bun run scripts/build-lib-bundle.ts",
268
262
 
269
- "build:cli-bundle": "bun build src/cli.ts --entry-naming \"[dir]/[name].bundle.[ext]\" --outdir dist --target node --format esm --minify --sourcemap=external",
270
-
271
263
  "typecheck": "tsc --noEmit",
272
264
 
273
265
  // runs src/dev.ts in watch mode
@@ -322,14 +314,21 @@ For CLI packages, add the following to `package.json`:
322
314
 
323
315
  The key question to ask is: **does my library retain its own URL at runtime?** Everything else follows from it.
324
316
 
317
+ ```bash
318
+ # placeholder:
319
+ # <@SCOPE: <@SCOPE>
320
+ # <LIB_NAME: <LIB_NAME>
321
+ # <VERSION: <VERSION>
322
+ ```
323
+
325
324
  ### Externalized - loaded from CDN or `node_modules/`
326
325
 
327
326
  The consumer does not bundle the library. It is loaded as a discrete module at runtime. Module identity is preserved regardless of the URL form:
328
327
 
329
328
  ```
330
- https://cdn.jsdelivr.net/npm/@scope/lib-name@1.0.0/dist/index.js
331
- file:///project/node_modules/@scope/lib-name/dist/index.js
332
- https://your-own-cdn.com/lib-name/index.js
329
+ https://cdn.jsdelivr.net/npm/<@SCOPE>/<LIB_NAME>@<VERSION>/dist/index.js
330
+ file:///project/node_modules/<@SCOPE>/<LIB_NAME>/dist/index.js
331
+ https://your-own-cdn.com/<LIB_NAME>/index.js
333
332
  ```
334
333
 
335
334
  `import.meta.url` is reliable in all these cases. `fetch()` is the correct I/O mechanism because it accepts both `https://` and `file://` URLs, making it universally correct for isomorphic (`--target node` or `--target browser`) libraries.
@@ -361,12 +360,12 @@ Place all runtime assets under a scoped directory that mirrors the package name:
361
360
 
362
361
  ```
363
362
  assets/
364
- └── @scope/
365
- └── lib-name/
366
- └── <ASSETS>
363
+ └── <@SCOPE>/
364
+ └── <LIB_NAME>/
365
+ └── ...
367
366
  ```
368
367
 
369
- This prevents naming collisions when multiple libraries are bundled into the same consumer app. Each library's assets live under their own namespace; no library can shadow another's files.
368
+ This also prevents naming collisions when multiple libraries are bundled into the same consumer app. Each library's assets live under their own namespace; no library can shadow another's files.
370
369
 
371
370
  Add `assets/` to the `files` field in `package.json` so that the assets are included in the published package:
372
371
 
@@ -385,13 +384,13 @@ Construct asset URLs directly from `import.meta.url`.
385
384
 
386
385
  ```typescript
387
386
  const packageUrl = new URL('../', import.meta.url);
388
- const assetsUrl = new URL('assets/@scope/lib-name/', packageUrl);
387
+ const assetsUrl = new URL('assets/<@SCOPE>/<LIB_NAME>/', packageUrl);
389
388
 
390
389
  // for --target browser
391
390
  const asset = await fetch(new URL('<ASSET>', assetsUrl)).then(r => r.json());
392
391
 
393
392
  // for --target node
394
- import { readFile } from 'node:fs/promises';
393
+ import { readFile } from 'fs/promises';
395
394
  import { fileURLToPath } from 'url';
396
395
  const asset = JSON.parse(await readFile(fileURLToPath(new URL('<ASSET>', assetsUrl)), 'utf-8'));
397
396
  ```
@@ -399,14 +398,9 @@ const asset = JSON.parse(await readFile(fileURLToPath(new URL('<ASSET>', assetsU
399
398
  ### README statement for library consumers
400
399
 
401
400
  ```markdown
402
- <!-- placeholder:
403
- <SCOPE: <SCOPE>
404
- <LIB_NAME: <LIB_NAME>
405
- -->
406
-
407
401
  ## Asset resolution
408
402
 
409
- This library resolves assets at runtime using `import.meta.url`. If you bundle this library into your application, copy `node_modules/<SCOPE>/<LIB_NAME>/assets/<SCOPE>/<LIB_NAME>/` into your build output directory alongside your bundle.
403
+ This library resolves assets at runtime using `import.meta.url`. If you bundle this library into your application, copy `node_modules/<@SCOPE>/<LIB_NAME>/assets/<@SCOPE>/<LIB_NAME>/` into your build output directory alongside your bundle.
410
404
  ```
411
405
 
412
406
  #### When the library is bundled by the consumer
@@ -417,12 +411,12 @@ The consumer must copy the assets into their build output at the same relative p
417
411
  consumer output/
418
412
  ├── bundle.js ← import.meta.url points here
419
413
  └── assets/
420
- └── @scope/
421
- └── lib-name/
422
- └── <ASSETS> ← copied; relative path preserved
414
+ └── <@SCOPE>/
415
+ └── <LIB_NAME>/
416
+ └── ... ← copied; relative path preserved
423
417
  ```
424
418
 
425
- From the bundle's perspective `assets/@scope/lib-name/` is at the same directory level as `bundle.js`, so `new URL('assets/@scope/lib-name/<ASSETS>', import.meta.url)` resolves correctly. No code configuration is needed - only the file copy.
419
+ From the bundle's perspective `assets/<@SCOPE>/<LIB_NAME>/` is at the same directory level as `bundle.js`, so `new URL('assets/<@SCOPE>/<LIB_NAME>/...', import.meta.url)` resolves correctly. No code configuration is needed - only the file copy.
426
420
 
427
421
  ## `src/dev.ts`
428
422
 
@@ -431,13 +425,13 @@ Development scratchpad - not published, excluded from `tsconfig.build.json`. Run
431
425
  # DevOps
432
426
 
433
427
  ```bash
434
- # remove dist/ and tsconfig.build.tsbuildinfo
428
+ # remove dist/ and tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo
435
429
  bun run clean
436
430
 
437
431
  # remove dist/ only
438
432
  bun run clean:dist
439
433
 
440
- # remove tsconfig.build.tsbuildinfo only
434
+ # remove tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo only
441
435
  bun run clean:tsbuildinfo
442
436
 
443
437
  # compile + bundle
@@ -459,15 +453,6 @@ bun run dist/cli.bundle.js -- example
459
453
 
460
454
  ## Publish
461
455
 
462
- See the following sources to configure the target registry and authentication.
463
-
464
- - [Configuring npm - `npmrc`](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc)
465
- - [Bun package manager - `install.registry`](https://bun.com/docs/runtime/bunfig#install-scopes)
466
-
467
- ⚠️ Package Scope and the authentication for the target registry must be aligned.
468
-
469
- ### `npmjs.org`
470
-
471
456
  Publish to the public npm registry.
472
457
 
473
458
  ```powershell
@@ -476,26 +461,3 @@ npm login
476
461
  # publish
477
462
  bun publish --registry https://registry.npmjs.org/ --access public
478
463
  ```
479
-
480
- ### Custom registry
481
-
482
- ```bash
483
- # placeholder:
484
- # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
485
- # <REGISTRY_URL: <REGISTRY_URL>
486
- # <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
487
- ```
488
-
489
- `~/.bunfig.toml` or `bunfig.toml`:
490
-
491
- ```toml
492
- [install.scopes]
493
- "<SCOPE_WITHOUT_AT>" = { url = "<REGISTRY_URL>", token = "$BUN_PUBLISH_AUTH_TOKEN" }
494
- ```
495
-
496
- ```powershell
497
- # authenticate
498
- $env:BUN_PUBLISH_AUTH_TOKEN = "<BUN_PUBLISH_AUTH_TOKEN>"
499
- # publish
500
- bun publish
501
- ```
package/buildinfo.txt CHANGED
@@ -1 +1 @@
1
- 0.6.0+bf23035
1
+ 0.6.1+f14d02f
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["..\\src\\cli.ts", "..\\src\\constants.ts"],
4
4
  "sourcesContent": [
5
- "#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';\r\nimport { resolve, basename } from 'path';\r\nimport {\r\n templatePath,\r\n changelogPath,\r\n buildinfoPath,\r\n readmePath\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument) throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templatePath, destinationPath, { recursive: true });\r\n cpSync(changelogPath, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoPath, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmePath, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n",
5
+ "#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';\r\nimport { resolve } from 'path';\r\nimport {\r\n templatePath,\r\n changelogPath,\r\n buildinfoPath,\r\n readmePath\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument) throw new Error('Package name argument is required. Usage: `create-ts-lib <package-name>`');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templatePath, destinationPath, { recursive: true });\r\n cpSync(changelogPath, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoPath, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmePath, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n",
6
6
  "import { resolve } from 'path';\r\nimport { fileURLToPath } from 'url';\r\n\r\n\r\nexport const packageUrl: URL = new URL('../', import.meta.url);\r\nexport const packagePath: string = resolve(fileURLToPath(packageUrl));\r\n\r\nexport const templatePath: string = resolve(packagePath, 'template/');\r\n\r\nexport const changelogPath: string = resolve(packagePath, 'CHANGELOG.md');\r\nexport const buildinfoPath: string = resolve(packagePath, 'buildinfo.txt');\r\nexport const readmePath: string = resolve(packagePath, 'README.md');\r\n"
7
7
  ],
8
8
  "mappings": ";AAEA,iBAAS,kBAAQ,gBAAc,mBAAY,WAC3C,kBAAS,aCHT,kBAAS,aACT,wBAAS,YAGF,IAAM,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAChD,EAAsB,EAAQ,EAAc,CAAU,CAAC,EAEvD,EAAuB,EAAQ,EAAa,WAAW,EAEvD,EAAwB,EAAQ,EAAa,cAAc,EAC3D,EAAwB,EAAQ,EAAa,eAAe,EAC5D,EAAqB,EAAQ,EAAa,WAAW,EDClE,GAAI,CAEA,IAAM,EAAsB,QAAQ,KAAK,GACzC,GAAI,CAAC,EAAqB,MAAU,MAAM,0EAA0E,EACpH,IAAM,EAAc,EAAoB,QAAQ,MAAO,GAAG,EAEpD,EAAkB,EAAQ,QAAQ,IAAI,EAAG,CAAW,EAE1D,EAAO,EAAc,EAAiB,CAAE,UAAW,EAAK,CAAC,EACzD,EAAO,EAAe,EAAQ,EAAiB,uBAAuB,CAAC,EACvE,EAAO,EAAe,EAAQ,EAAiB,wBAAwB,CAAC,EACxE,EAAO,EAAY,EAAQ,EAAiB,oBAAoB,CAAC,EAEjE,IAAM,EAAkB,EAAQ,EAAiB,cAAc,EACzD,EAAc,KAAK,MAAM,EAAa,EAAiB,OAAO,CAAC,EACrE,EAAY,KAAO,EACnB,EAAc,EAAiB,KAAK,UAAU,EAAa,KAAM,CAAC,CAAC,EAEnE,EAAW,EAAQ,EAAiB,WAAW,EAAG,EAAQ,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmD,yBAAuC,KAAe,EAGzH,MAAO,EAAO,CACV,IAAM,EAAM,aAAiB,MAAQ,EAAY,MAAM,OAAO,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAU,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC",
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { cpSync, readFileSync, renameSync, writeFileSync } from 'fs';
3
- import { resolve, basename } from 'path';
3
+ import { resolve } from 'path';
4
4
  import { templatePath, changelogPath, buildinfoPath, readmePath } from './constants.js';
5
5
  try {
6
6
  const packageNameArgument = process.argv[2];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temir.ra/create-ts-lib",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Typescript library template",
5
5
  "author": "temir.ra",
6
6
  "license": "MIT",
@@ -5,9 +5,8 @@
5
5
  ## Table of Contents
6
6
 
7
7
  1. [Quick Start](#quick-start)
8
- 2. [AI Assistant Context](#ai-assistant-context)
9
- 3. [Documentation](#documentation)
10
- 4. [DevOps](#devops)
8
+ 2. [Documentation](#documentation)
9
+ 3. [DevOps](#devops)
11
10
  1. [Change Management](#change-management)
12
11
  2. [Publish](#publish)
13
12
  1. [npmjs.org](#npmjsorg)
@@ -16,13 +15,13 @@
16
15
  # Quick Start
17
16
 
18
17
  ```bash
19
- # remove dist/ and tsconfig.build.tsbuildinfo
18
+ # remove dist/ and tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo
20
19
  bun run clean
21
20
 
22
21
  # remove dist/ only
23
22
  bun run clean:dist
24
23
 
25
- # remove tsconfig.build.tsbuildinfo only
24
+ # remove tsconfig.tsbuildinfo and tsconfig.build.tsbuildinfo only
26
25
  bun run clean:tsbuildinfo
27
26
 
28
27
  # compile + bundle
@@ -35,30 +34,10 @@ bun run tests
35
34
  bun run dev
36
35
  ```
37
36
 
38
- **Publish** - see [Publish](#publish).
39
-
40
- # AI Assistant Context
41
-
42
- To generate an AI coding assistant context file for this project:
43
-
44
- > Generate an AI coding assistant context file. `README-template.md` is available now and documents the architectural conventions of this package — use it as your primary source. The generated context file must be self-contained: `README-template.md` will be deleted after context generation, so do not reference it in the output. Give particular attention to: the dual tsconfig setup and the import constraints it imposes, the `#src/*.js` alias and where it may and may not be used, the custom `entrypoint` export condition, and the asset resolution contract.
45
-
46
37
  # Documentation
47
38
 
48
39
  *&lt;DOCUMENTATION&gt;*
49
40
 
50
- ## Asset Resolution
51
-
52
- *&lt;!-- Remove this section if the library has no runtime assets. Replace `@scope/lib-name` throughout with the actual package name. --&gt;*
53
-
54
- Assets are placed under `assets/@scope/lib-name/` (scoped to the package name to prevent collisions). They are resolved at runtime via `import.meta.url` and loaded with `fetch()` (browser) or `readFile` (Node). `assets/` must be listed in `files` in `package.json`.
55
-
56
- `import.meta.url` is reliable when the library is loaded as a discrete module (from CDN or `node_modules/`). When the consumer bundles the library, they must copy the assets - see below.
57
-
58
- ### For consumers bundling this library
59
-
60
- Copy `node_modules/@scope/lib-name/assets/` into your build output alongside the bundle, preserving the relative path. No code configuration is required - only the file copy.
61
-
62
41
  # DevOps
63
42
 
64
43
  ## Change Management
@@ -95,9 +74,9 @@ bun publish --registry https://registry.npmjs.org/ --access public
95
74
 
96
75
  ```bash
97
76
  # placeholder:
98
- # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
99
- # <REGISTRY_URL: <REGISTRY_URL>
100
- # <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
77
+ # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
78
+ # <REGISTRY_URL: <REGISTRY_URL>
79
+ # <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
101
80
  ```
102
81
 
103
82
  `~/.bunfig.toml` or `bunfig.toml`: