@temir.ra/create-ts-lib 0.7.4 → 0.7.6
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 +11 -0
- package/README.md +84 -100
- package/buildinfo.txt +1 -1
- package/package.json +2 -2
- package/template/README.md +1 -0
- package/template/package.json +2 -3
- package/template/tests/buildinfo.test.ts +1 -1
- package/template/tsconfig.json +3 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Version 0
|
|
2
2
|
|
|
3
|
+
## 0.7.6
|
|
4
|
+
|
|
5
|
+
1. Updated `typescript` to `6.0.3`.
|
|
6
|
+
2. Cleaned up minor `README.md` inconsistencies.
|
|
7
|
+
3. Aligned wording with [`RFC 2119`](https://datatracker.ietf.org/doc/html/rfc2119).
|
|
8
|
+
4. Updated files from `template` template.
|
|
9
|
+
|
|
10
|
+
## 0.7.5
|
|
11
|
+
|
|
12
|
+
1. Updated files from `@temir.ra/template@0.1.6` template.
|
|
13
|
+
|
|
3
14
|
## 0.7.4
|
|
4
15
|
|
|
5
16
|
1. Updated `keywords` in `template/package.json`.
|
package/README.md
CHANGED
|
@@ -7,14 +7,10 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
|
|
|
7
7
|
1. [Quick Start](#quick-start)
|
|
8
8
|
2. [Documentation](#documentation)
|
|
9
9
|
1. [`package.json`](#packagejson)
|
|
10
|
-
2. [
|
|
11
|
-
3. [`tsconfig.json`](#tsconfigjson)
|
|
12
|
-
4. [TSC Compilation](#tsc-compilation)
|
|
13
|
-
1. [`tsconfig.build.json`](#tsconfigbuildjson)
|
|
14
|
-
2. [`package.json`](#packagejson-1)
|
|
15
|
-
5. [Script `scripts/build-bundle.ts`](#script-scriptsbuild-bundlets)
|
|
10
|
+
2. [Script `scripts/build-bundle.ts`](#script-scriptsbuild-bundlets)
|
|
16
11
|
1. [CDN Map `scripts/cdn-rewrite-map.json`](#cdn-map-scriptscdn-rewrite-mapjson)
|
|
17
|
-
|
|
12
|
+
3. [`tsconfig.build.json`](#tsconfigbuildjson)
|
|
13
|
+
4. [Asset Resolution](#asset-resolution)
|
|
18
14
|
1. [Externalized - loaded from CDN or `node_modules/`](#externalized---loaded-from-cdn-or-node_modules)
|
|
19
15
|
2. [Bundled - absorbed into the consumer's output](#bundled---absorbed-into-the-consumers-output)
|
|
20
16
|
3. [Contract](#contract)
|
|
@@ -22,6 +18,7 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
|
|
|
22
18
|
2. [Accessing assets](#accessing-assets)
|
|
23
19
|
3. [README statement for library consumers](#readme-statement-for-library-consumers)
|
|
24
20
|
4. [When the library is bundled by the consumer](#when-the-library-is-bundled-by-the-consumer)
|
|
21
|
+
5. [`"bin"` field in `package.json`](#bin-field-in-packagejson)
|
|
25
22
|
3. [DevOps](#devops)
|
|
26
23
|
1. [Change Management](#change-management)
|
|
27
24
|
2. [Publish](#publish)
|
|
@@ -85,6 +82,7 @@ The generated package is pre-configured with `build:bundle` only. See [TSC Compi
|
|
|
85
82
|
"type": "module",
|
|
86
83
|
|
|
87
84
|
// package entry points
|
|
85
|
+
// multiple entry points can be configured (".", "./module/", etc.)
|
|
88
86
|
//
|
|
89
87
|
// scripts/build-bundle.ts (non-standard) export condition:
|
|
90
88
|
// "entrypoint" - locates the source entry point for bundling
|
|
@@ -92,13 +90,13 @@ The generated package is pre-configured with `build:bundle` only. See [TSC Compi
|
|
|
92
90
|
// standard export conditions:
|
|
93
91
|
// "types" - TypeScript consumers; resolves to the declaration files;
|
|
94
92
|
// "browser" - browser bundler consumers; resolves to the bundled output
|
|
95
|
-
// "import" - ESM consumers; resolves to the compiled
|
|
93
|
+
// "import" - ESM consumers; resolves to the bundled/compiled output
|
|
96
94
|
"exports": {
|
|
97
95
|
".": {
|
|
98
96
|
"entrypoint": "./src/index.ts",
|
|
99
97
|
"types": "./dist/index.d.ts",
|
|
100
98
|
"browser": "./dist/index.bundle.js",
|
|
101
|
-
"import": "./dist/index.js"
|
|
99
|
+
"import": "./dist/index.bundle.js"
|
|
102
100
|
}
|
|
103
101
|
},
|
|
104
102
|
|
|
@@ -143,7 +141,7 @@ The generated package is pre-configured with `build:bundle` only. See [TSC Compi
|
|
|
143
141
|
"prebuild": "bun run buildinfo",
|
|
144
142
|
|
|
145
143
|
// convenience script to run the build steps in sequence
|
|
146
|
-
"build": "bun run build:
|
|
144
|
+
"build": "bun run build:bundle && bun run build:tsc && bun run build:cli-bundle",
|
|
147
145
|
|
|
148
146
|
// compiles the library to declaration files and ESM JavaScript in dist/
|
|
149
147
|
"build:tsc": "tsc --project tsconfig.build.json",
|
|
@@ -161,89 +159,29 @@ The generated package is pre-configured with `build:bundle` only. See [TSC Compi
|
|
|
161
159
|
|
|
162
160
|
It is highly recommended to include `tests/` in the `files` field. Note, that `tests/` is not included by default in the generated `package.json`.
|
|
163
161
|
|
|
164
|
-
##
|
|
165
|
-
|
|
166
|
-
For CLI packages, add the following to `package.json`:
|
|
167
|
-
|
|
168
|
-
```json
|
|
169
|
-
{
|
|
170
|
-
// ... ,
|
|
171
|
-
"bin": "./dist/cli.bundle.js",
|
|
172
|
-
"scripts": {
|
|
173
|
-
// ... ,
|
|
174
|
-
"build": "... && bun run build:cli-bundle",
|
|
175
|
-
// ... ,
|
|
176
|
-
"build:cli-bundle": "bun build src/cli.ts --entry-naming \"[dir]/[name].bundle.[ext]\" --outdir dist --target node --format esm --minify --sourcemap=external"
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
`src/cli.ts` must begin with a hashbang so the OS knows which interpreter to invoke when the binary is executed directly. Bun preserves it in the bundled output.
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
#!/usr/bin/env node
|
|
185
|
-
```
|
|
162
|
+
## Script `scripts/build-bundle.ts`
|
|
186
163
|
|
|
187
|
-
|
|
164
|
+
Bundles the library to ESM and IIFE formats. Entry points are resolved from the `entrypoint` condition in the `exports` field of `package.json`. Note, the `entrypoint` condition is a custom, non-standard export condition used solely for build tooling.
|
|
188
165
|
|
|
189
|
-
|
|
166
|
+
Import specifiers can be rewritten to CDN URLs via `scripts/cdn-rewrite-map.json`.
|
|
190
167
|
|
|
191
|
-
|
|
168
|
+
### CDN Map `scripts/cdn-rewrite-map.json`
|
|
192
169
|
|
|
193
|
-
|
|
170
|
+
Maps import specifiers to CDN URLs. During bundling, matching specifiers in source files are rewritten to their CDN equivalents.
|
|
194
171
|
|
|
195
|
-
|
|
172
|
+
`<VERSION>` in a URL is replaced with the version of the matching package from `package.json`.
|
|
196
173
|
|
|
197
174
|
```json
|
|
198
175
|
{
|
|
199
|
-
|
|
200
|
-
"compilerOptions": {
|
|
201
|
-
|
|
202
|
-
// ... ,
|
|
203
|
-
|
|
204
|
-
// emit .d.ts declaration files
|
|
205
|
-
"declaration": true,
|
|
206
|
-
|
|
207
|
-
// emit .d.ts.map files mapping declarations back to source
|
|
208
|
-
"declarationMap": true,
|
|
209
|
-
|
|
210
|
-
// emit only .d.ts files, no JavaScript; overridden in tsconfig.build.json
|
|
211
|
-
"emitDeclarationOnly": true,
|
|
212
|
-
|
|
213
|
-
// output directory for emitted files
|
|
214
|
-
"outDir": "./dist"
|
|
215
|
-
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
"include": [
|
|
219
|
-
// ... ,
|
|
220
|
-
// include `scripts/**/*.json` for script configuration files
|
|
221
|
-
"scripts/**/*.json",
|
|
222
|
-
// include `src/**/*.ts` for source files
|
|
223
|
-
"src/**/*.ts"
|
|
224
|
-
],
|
|
225
|
-
"exclude": [
|
|
226
|
-
// ... ,
|
|
227
|
-
// exclude `dist/`
|
|
228
|
-
"dist"
|
|
229
|
-
]
|
|
230
|
-
|
|
176
|
+
"import-specifier": "https://cdn.jsdelivr.net/npm/package-name@<VERSION>/dist/index.bundle.js"
|
|
231
177
|
}
|
|
232
178
|
```
|
|
233
179
|
|
|
234
|
-
|
|
180
|
+
## `tsconfig.build.json`
|
|
235
181
|
|
|
236
|
-
|
|
182
|
+
`tsconfig.json` provided by [`workspace` template](https://www.npmjs.com/package/@temir.ra/create-workspace) is intended for development only. `tsconfig.build.json` extends it with settings for compiling the source files for distribution.
|
|
237
183
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
### `tsconfig.build.json`
|
|
241
|
-
|
|
242
|
-
Extends `tsconfig.json`, narrowing scope to `src/` only and switching to `nodenext` module resolution for strict ESM compliance.
|
|
243
|
-
|
|
244
|
-
Enables JavaScript output alongside declaration files for distribution.
|
|
245
|
-
|
|
246
|
-
Development files (`dev.ts`, `tests/`, `scripts/`) are excluded.
|
|
184
|
+
See [`create-workspace` README](https://www.npmjs.com/package/@temir.ra/create-workspace#tsconfigjson) and [tsconfig.json](https://www.typescriptlang.org/tsconfig) for detailed explanations of all options.
|
|
247
185
|
|
|
248
186
|
```json
|
|
249
187
|
{
|
|
@@ -253,14 +191,23 @@ Development files (`dev.ts`, `tests/`, `scripts/`) are excluded.
|
|
|
253
191
|
"compilerOptions": {
|
|
254
192
|
|
|
255
193
|
// narrows root to src/ for distribution output
|
|
256
|
-
"rootDir": "./src",
|
|
194
|
+
"rootDir": "./src/",
|
|
257
195
|
|
|
258
196
|
// nodenext enforces strict ESM compliance; imports must use explicit .js file extensions
|
|
259
197
|
"module": "nodenext",
|
|
260
198
|
"moduleResolution": "nodenext",
|
|
261
199
|
|
|
262
|
-
// emit
|
|
263
|
-
"
|
|
200
|
+
// emit .d.ts declaration files
|
|
201
|
+
"declaration": true,
|
|
202
|
+
|
|
203
|
+
// emit .d.ts.map files mapping declarations back to source
|
|
204
|
+
"declarationMap": true,
|
|
205
|
+
|
|
206
|
+
// emit only .d.ts files, no JavaScript
|
|
207
|
+
"emitDeclarationOnly": true,
|
|
208
|
+
|
|
209
|
+
// output directory for emitted files
|
|
210
|
+
"outDir": "./dist/"
|
|
264
211
|
|
|
265
212
|
},
|
|
266
213
|
|
|
@@ -270,10 +217,10 @@ Development files (`dev.ts`, `tests/`, `scripts/`) are excluded.
|
|
|
270
217
|
],
|
|
271
218
|
// exclude development files and directories from distribution
|
|
272
219
|
"exclude": [
|
|
273
|
-
"node_modules",
|
|
274
|
-
"dist",
|
|
275
|
-
"tests",
|
|
276
|
-
"scripts"
|
|
220
|
+
"node_modules/",
|
|
221
|
+
"dist/",
|
|
222
|
+
"tests/",
|
|
223
|
+
"scripts/"
|
|
277
224
|
]
|
|
278
225
|
|
|
279
226
|
}
|
|
@@ -286,27 +233,40 @@ Development files (`dev.ts`, `tests/`, `scripts/`) are excluded.
|
|
|
286
233
|
// ... ,
|
|
287
234
|
"scripts": {
|
|
288
235
|
// ... ,
|
|
289
|
-
"build": "
|
|
236
|
+
"build": "... && bun run build:tsc",
|
|
290
237
|
"build:tsc": "tsc --project tsconfig.build.json"
|
|
291
238
|
}
|
|
292
239
|
}
|
|
293
240
|
```
|
|
294
241
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
Bundles the library to ESM and IIFE formats. Entry points are resolved from the `entrypoint` condition in the `exports` field of `package.json`. Note, the `entrypoint` condition is a custom, non-standard export condition used solely for build tooling.
|
|
298
|
-
|
|
299
|
-
Import specifiers can be rewritten to CDN URLs via `scripts/cdn-rewrite-map.json`.
|
|
300
|
-
|
|
301
|
-
### CDN Map `scripts/cdn-rewrite-map.json`
|
|
242
|
+
Exports condition `import` may point to the compiled output instead of the bundled output `./dist/index.bundle.js`:
|
|
302
243
|
|
|
303
|
-
|
|
244
|
+
```json
|
|
245
|
+
{
|
|
246
|
+
// ... ,
|
|
247
|
+
"exports": {
|
|
248
|
+
".": {
|
|
249
|
+
// ... ,
|
|
250
|
+
"import": "./dist/index.js"
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
// ... ,
|
|
254
|
+
}
|
|
255
|
+
```
|
|
304
256
|
|
|
305
|
-
|
|
257
|
+
When `"declaration": true`, then exports condition `types` can be added to point to the declaration files:
|
|
306
258
|
|
|
307
259
|
```json
|
|
308
260
|
{
|
|
309
|
-
|
|
261
|
+
// ... ,
|
|
262
|
+
"exports": {
|
|
263
|
+
".": {
|
|
264
|
+
// ... ,
|
|
265
|
+
"types": "./dist/index.d.ts",
|
|
266
|
+
// ... ,
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
// ... ,
|
|
310
270
|
}
|
|
311
271
|
```
|
|
312
272
|
|
|
@@ -386,6 +346,7 @@ Construct asset URLs directly from `import.meta.url`.
|
|
|
386
346
|
const packageUrl = new URL('../', import.meta.url);
|
|
387
347
|
const assetsUrl = new URL('assets/<@SCOPE>/<LIB_NAME>/', packageUrl);
|
|
388
348
|
|
|
349
|
+
|
|
389
350
|
// for --target browser
|
|
390
351
|
const asset = await fetch(new URL('<ASSET>', assetsUrl)).then(r => r.json());
|
|
391
352
|
|
|
@@ -418,17 +379,40 @@ consumer output/
|
|
|
418
379
|
|
|
419
380
|
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.
|
|
420
381
|
|
|
382
|
+
## `"bin"` field in `package.json`
|
|
383
|
+
|
|
384
|
+
For CLI packages, add the following to `package.json`:
|
|
385
|
+
|
|
386
|
+
```json
|
|
387
|
+
{
|
|
388
|
+
// ... ,
|
|
389
|
+
"bin": "./dist/cli.bundle.js",
|
|
390
|
+
"scripts": {
|
|
391
|
+
// ... ,
|
|
392
|
+
"build": "... && bun run build:cli-bundle",
|
|
393
|
+
"build:cli-bundle": "bun build src/cli.ts --entry-naming \"[dir]/[name].bundle.[ext]\" --outdir dist --target node --format esm --minify --sourcemap=external"
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
`src/cli.ts` must begin with a hashbang so the OS knows which interpreter to invoke when the binary is executed directly. Bun preserves it in the bundled output.
|
|
399
|
+
|
|
400
|
+
```typescript
|
|
401
|
+
#!/usr/bin/env node
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
If the package exports a CLI only and is not intended to be imported in other packages, the `exports` field can be omitted.
|
|
405
|
+
|
|
421
406
|
# DevOps
|
|
422
407
|
|
|
423
408
|
```bash
|
|
409
|
+
bun update
|
|
424
410
|
bun install
|
|
425
411
|
|
|
426
412
|
bun run clean
|
|
427
413
|
bun run build
|
|
428
414
|
bun run tests
|
|
429
415
|
|
|
430
|
-
bun run --watch scripts/dev.ts
|
|
431
|
-
|
|
432
416
|
# see publish section for publish instructions
|
|
433
417
|
```
|
|
434
418
|
|
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.7.
|
|
1
|
+
0.7.6+b2fa591
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temir.ra/create-ts-lib",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"description": "A template for a distributable TypeScript library package.",
|
|
5
5
|
"author": "temir.ra",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/bun": "latest",
|
|
46
|
-
"typescript": "^6.0.
|
|
46
|
+
"typescript": "^6.0.3"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/template/README.md
CHANGED
package/template/package.json
CHANGED
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"entrypoint": "./src/index.ts",
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
20
|
"browser": "./dist/index.bundle.js",
|
|
22
|
-
"import": "./dist/index.js"
|
|
21
|
+
"import": "./dist/index.bundle.js"
|
|
23
22
|
}
|
|
24
23
|
},
|
|
25
24
|
"imports": {
|
|
@@ -47,6 +46,6 @@
|
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"@types/bun": "latest",
|
|
50
|
-
"typescript": "^6.0.
|
|
49
|
+
"typescript": "^6.0.3"
|
|
51
50
|
}
|
|
52
51
|
}
|
package/template/tsconfig.json
CHANGED
|
@@ -19,11 +19,7 @@
|
|
|
19
19
|
"bun"
|
|
20
20
|
],
|
|
21
21
|
"forceConsistentCasingInFileNames": true,
|
|
22
|
-
"resolveJsonModule": true
|
|
23
|
-
"declaration": true,
|
|
24
|
-
"declarationMap": true,
|
|
25
|
-
"emitDeclarationOnly": true,
|
|
26
|
-
"outDir": "./dist"
|
|
22
|
+
"resolveJsonModule": true
|
|
27
23
|
},
|
|
28
24
|
"include": [
|
|
29
25
|
"scripts/**/*.ts",
|
|
@@ -32,7 +28,7 @@
|
|
|
32
28
|
"tests/**/*.ts"
|
|
33
29
|
],
|
|
34
30
|
"exclude": [
|
|
35
|
-
"node_modules",
|
|
36
|
-
"dist"
|
|
31
|
+
"node_modules/",
|
|
32
|
+
"dist/"
|
|
37
33
|
]
|
|
38
34
|
}
|