@temir.ra/create-ts-lib 0.7.6 → 0.8.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,15 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.8.1
4
+
5
+ 1. Added `DOM` to the `lib` array in the generated `tsconfig.json`.
6
+
7
+ ## 0.8.0
8
+
9
+ 1. Updated wording in the Publish section of the generated README.
10
+ 2. `build:tsc` step is now generated per default.
11
+ 3. Added `./constants` entrypoint to `package.json`.
12
+
3
13
  ## 0.7.6
4
14
 
5
15
  1. Updated `typescript` to `6.0.3`.
package/README.md CHANGED
@@ -143,12 +143,12 @@ The generated package is pre-configured with `build:bundle` only. See [TSC Compi
143
143
  // convenience script to run the build steps in sequence
144
144
  "build": "bun run build:bundle && bun run build:tsc && bun run build:cli-bundle",
145
145
 
146
- // compiles the library to declaration files and ESM JavaScript in dist/
147
- "build:tsc": "tsc --project tsconfig.build.json",
148
-
149
146
  // bundles the library into ESM and IIFE formats for distribution
150
147
  "build:bundle": "bun run scripts/build-bundle.ts",
151
148
 
149
+ // compiles the library to declaration files and ESM JavaScript in dist/
150
+ "build:tsc": "tsc --project tsconfig.build.json",
151
+
152
152
  // bundles the CLI into a single file for distribution; requires the "bin" field to be set to the bundled output
153
153
  "build:cli-bundle": "bun build src/cli.ts --entry-naming \"[dir]/[name].bundle.[ext]\" --outdir dist --target node --format esm --minify --sourcemap=external"
154
154
 
@@ -239,7 +239,7 @@ See [`create-workspace` README](https://www.npmjs.com/package/@temir.ra/create-w
239
239
  }
240
240
  ```
241
241
 
242
- Exports condition `import` may point to the compiled output instead of the bundled output `./dist/index.bundle.js`:
242
+ Exports condition `import` may point to the compiled output instead of the bundled output `./dist/index.bundle.js` if `"emitDeclarationOnly": false`:
243
243
 
244
244
  ```json
245
245
  {
@@ -295,7 +295,7 @@ https://your-own-cdn.com/<LIB_NAME>/index.js
295
295
 
296
296
  ### Bundled - absorbed into the consumer's output
297
297
 
298
- The consumer's bundler absorbs the library into their own output. Module identity is destroyed - `import.meta.url` now points to the consumer's bundle, not the library's. However, **the path relationship can be preserved by convention**: if the consumer copies the library's assets into their build output at the same relative path the library expects, `import.meta.url` resolution continues to work correctly.
298
+ The consumer's bundler absorbs the library into their own output. Module identity is destroyed - `import.meta.url` now points to the consumer's bundle, not the library's. However, **the path relationship can be preserved by convention**: if the consumer copies the library's assets into their output directory at the same relative path the library expects, `import.meta.url` resolution continues to work correctly.
299
299
 
300
300
  ### Contract
301
301
 
@@ -312,7 +312,7 @@ If the library has runtime assets, the following contract applies:
312
312
  1. **Copy the assets** - see [When the library is bundled by the consumer](#when-the-library-is-bundled-by-the-consumer) below.
313
313
  2. **Ensure the assets are served**
314
314
  - if the consumer is a web server, ensure the copied assets are served as static files
315
- - if the consumer is a bundler, ensure the copied assets are included in the bundle output
315
+ - if the consumer is a bundler, ensure the copied assets are included in the output directory
316
316
 
317
317
  #### Scoped assets directory convention
318
318
 
@@ -325,35 +325,55 @@ assets/
325
325
  └── ...
326
326
  ```
327
327
 
328
- 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.
329
-
330
328
  Add `assets/` to the `files` field in `package.json` so that the assets are included in the published package:
331
329
 
332
330
  ```json
331
+ {
332
+ // ... ,
333
333
  "files": [
334
- "dist",
335
- "CHANGELOG.md",
336
- "buildinfo.txt",
337
- "assets"
334
+ // ... ,
335
+ "assets/"
338
336
  ],
337
+ // ... ,
338
+ }
339
339
  ```
340
340
 
341
341
  #### Accessing assets
342
342
 
343
- Construct asset URLs directly from `import.meta.url`.
343
+ Construct asset URLs directly from `import.meta.url`:
344
344
 
345
345
  ```typescript
346
346
  const packageUrl = new URL('../', import.meta.url);
347
347
  const assetsUrl = new URL('assets/<@SCOPE>/<LIB_NAME>/', packageUrl);
348
348
 
349
+ // for `--target browser` and `--target node` (isomorphic)
350
+ const assetUrl = new URL('<ASSET>', assetsUrl);
351
+ const asset = await fetch(assetUrl).then(response => response.body);
349
352
 
350
- // for --target browser
351
- const asset = await fetch(new URL('<ASSET>', assetsUrl)).then(r => r.json());
352
-
353
- // for --target node
353
+ // for `--target node` only
354
354
  import { readFile } from 'fs/promises';
355
355
  import { fileURLToPath } from 'url';
356
- const asset = JSON.parse(await readFile(fileURLToPath(new URL('<ASSET>', assetsUrl)), 'utf-8'));
356
+ const assetUrl = new URL('<ASSET>', assetsUrl);
357
+ const assetPath = fileURLToPath(assetUrl);
358
+ const asset = await readFile(assetPath);
359
+ ```
360
+
361
+ The generated `./src/constants.ts` scaffolds the isomorphic approach and `./constants` is configured as an additional entry point in `package.json` for direct imports:
362
+
363
+ ```json
364
+ {
365
+ // ... ,
366
+ "exports": {
367
+ // ... ,
368
+ "./constants": {
369
+ "entrypoint": "./src/constants.ts",
370
+ "types": "./dist/constants.d.ts",
371
+ "browser": "./dist/constants.bundle.js",
372
+ "import": "./dist/constants.bundle.js"
373
+ }
374
+ },
375
+ // ... ,
376
+ }
357
377
  ```
358
378
 
359
379
  #### README statement for library consumers
@@ -361,7 +381,7 @@ const asset = JSON.parse(await readFile(fileURLToPath(new URL('<ASSET>', assetsU
361
381
  ```markdown
362
382
  ## Asset resolution
363
383
 
364
- 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.
384
+ This library resolves assets at runtime using `import.meta.url`. If you include this library into your bundle, copy `node_modules/<@SCOPE>/<LIB_NAME>/assets/<@SCOPE>/<LIB_NAME>/` to your output directory as `assets/<@SCOPE>/<LIB_NAME>/`.
365
385
  ```
366
386
 
367
387
  #### When the library is bundled by the consumer
package/buildinfo.txt CHANGED
@@ -1 +1 @@
1
- 0.7.6+b2fa591
1
+ 0.8.0+545e022
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temir.ra/create-ts-lib",
3
- "version": "0.7.6",
3
+ "version": "0.8.1",
4
4
  "description": "A template for a distributable TypeScript library package.",
5
5
  "author": "temir.ra",
6
6
  "license": "MIT",
@@ -67,6 +67,8 @@ bun publish --registry https://registry.npmjs.org/ --access public
67
67
 
68
68
  ### Custom registry
69
69
 
70
+ Publish to a custom registry.
71
+
70
72
  ```bash
71
73
  # placeholder:
72
74
  # <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
@@ -17,8 +17,15 @@
17
17
  "exports": {
18
18
  ".": {
19
19
  "entrypoint": "./src/index.ts",
20
+ "types": "./dist/index.d.ts",
20
21
  "browser": "./dist/index.bundle.js",
21
22
  "import": "./dist/index.bundle.js"
23
+ },
24
+ "./constants": {
25
+ "entrypoint": "./src/constants.ts",
26
+ "types": "./dist/constants.d.ts",
27
+ "browser": "./dist/constants.bundle.js",
28
+ "import": "./dist/constants.bundle.js"
22
29
  }
23
30
  },
24
31
  "imports": {
@@ -41,8 +48,9 @@
41
48
  "clean": "bun run clean:dist && bun run clean:tsbuildinfo",
42
49
  "tests": "bun test",
43
50
  "prebuild": "bun run buildinfo",
44
- "build": "bun run build:bundle",
45
- "build:bundle": "bun run scripts/build-bundle.ts"
51
+ "build": "bun run build:bundle && bun run build:tsc",
52
+ "build:bundle": "bun run scripts/build-bundle.ts",
53
+ "build:tsc": "tsc --project tsconfig.build.json"
46
54
  },
47
55
  "devDependencies": {
48
56
  "@types/bun": "latest",
@@ -0,0 +1,3 @@
1
+ export const packageUrl: URL = new URL('../', import.meta.url);
2
+ export const buildinfoUrl: URL = new URL('buildinfo.txt', packageUrl);
3
+ export const distUrl: URL = new URL('dist/', packageUrl);
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src/",
5
+ "module": "nodenext",
6
+ "moduleResolution": "nodenext",
7
+ "declaration": true,
8
+ "declarationMap": true,
9
+ "emitDeclarationOnly": true,
10
+ "outDir": "./dist/"
11
+ },
12
+ "include": [
13
+ "src/**/*.ts"
14
+ ],
15
+ "exclude": [
16
+ "node_modules/",
17
+ "dist/",
18
+ "tests/",
19
+ "scripts/"
20
+ ]
21
+ }
@@ -3,7 +3,8 @@
3
3
  "target": "ESNext",
4
4
  "module": "ESNext",
5
5
  "lib": [
6
- "ESNext"
6
+ "ESNext",
7
+ "DOM"
7
8
  ],
8
9
  "moduleResolution": "bundler",
9
10
  "strict": true,