@temir.ra/create-ts-lib 0.10.0 → 0.11.0-pre.12
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 +15 -0
- package/README.md +55 -61
- package/buildinfo.txt +1 -1
- package/dist/cli.bundle.js +2 -0
- package/dist/cli.bundle.js.map +7 -0
- package/package.json +49 -47
- package/template/README.md +28 -41
- package/template/package.json +22 -19
- package/template/scripts/dev.ts +1 -1
- package/template/src/constants.ts +3 -0
- package/template/tests/buildinfo.test.ts +11 -9
- package/template/tsconfig.json +1 -2
- package/tests/buildinfo.test.ts +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Version 0
|
|
2
2
|
|
|
3
|
+
## 0.11.0-pre.12
|
|
4
|
+
|
|
5
|
+
1. Synced template files with `workspace@0.7.0-pre.1` template.
|
|
6
|
+
2. Added more constants exports.
|
|
7
|
+
3. Refactored `buildinfo.test.ts`.
|
|
8
|
+
4. Included `tests/` in the published files.
|
|
9
|
+
5. Cleaned up minor `README.md` wording.
|
|
10
|
+
6. Updated `README.md` to reflect recent changes and clarify documentation.
|
|
11
|
+
7. Refactored the Publish section in the `README.md` to include documentation scaffolding.
|
|
12
|
+
8. Updated from `template@0.4.0-pre.9` template.
|
|
13
|
+
|
|
14
|
+
## 0.10.1
|
|
15
|
+
|
|
16
|
+
1. Fixed missing build output files.
|
|
17
|
+
|
|
3
18
|
## 0.10.0
|
|
4
19
|
|
|
5
20
|
1. Added `node:` prefix to imports.
|
package/README.md
CHANGED
|
@@ -27,22 +27,18 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
|
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
# placeholder:
|
|
30
|
-
# <NEW_PACKAGE: <NEW_PACKAGE>
|
|
31
30
|
# <TEMPLATE_PACKAGE_NAME: @temir.ra/create-ts-lib
|
|
32
31
|
# <TEMPLATE_NAME: @temir.ra/ts-lib
|
|
33
32
|
|
|
34
|
-
mkdir -p <NEW_PACKAGE>
|
|
35
|
-
cd <NEW_PACKAGE>
|
|
36
|
-
|
|
37
33
|
# print the latest version
|
|
38
|
-
|
|
34
|
+
npm info "@temir.ra/create-ts-lib" version
|
|
39
35
|
|
|
40
36
|
# create/update a package from the template in the current directory
|
|
41
|
-
|
|
37
|
+
npm create --no-install --no-git "@temir.ra/ts-lib@latest" .
|
|
42
38
|
|
|
43
39
|
# set metadata in package.json
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
npm install
|
|
46
42
|
```
|
|
47
43
|
|
|
48
44
|
# Documentation
|
|
@@ -52,7 +48,7 @@ The following sections explain the configurations and conventions baked into the
|
|
|
52
48
|
The major addition compared to the [`workspace` template](https://www.npmjs.com/package/@temir.ra/create-workspace) is a build pipeline for distributing the library. Two build strategies are supported:
|
|
53
49
|
|
|
54
50
|
- **Bundling** (`scripts/build-bundle.ts`) - bundles the library to ESM and IIFE formats using [`esbuild`](https://esbuild.github.io/).
|
|
55
|
-
- **TSC compilation** (`tsconfig.build.json` + `build:tsc`) - compiles the library to declaration files and ESM JavaScript using [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
|
|
51
|
+
- **TSC compilation** (`tsconfig.build.json` + `build:tsc`) - compiles the library to declaration files, and optionally ESM JavaScript, using [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
|
|
56
52
|
|
|
57
53
|
Both strategies can be combined.
|
|
58
54
|
|
|
@@ -70,9 +66,25 @@ The following fields are specific to this template:
|
|
|
70
66
|
// the package is anticipated to be published
|
|
71
67
|
"private": false,
|
|
72
68
|
|
|
69
|
+
// ... ,
|
|
70
|
+
|
|
73
71
|
// treats all .js files as ES modules; use .cjs extension for CommonJS files
|
|
74
72
|
"type": "module",
|
|
75
73
|
|
|
74
|
+
// files to include in the published package
|
|
75
|
+
"files": [
|
|
76
|
+
"scripts/buildinfo.ts",
|
|
77
|
+
"scripts/build-bundle.ts",
|
|
78
|
+
"scripts/cdn-rewrite-map.json",
|
|
79
|
+
"CHANGELOG.md",
|
|
80
|
+
"buildinfo.txt",
|
|
81
|
+
"dist/",
|
|
82
|
+
"tests/"
|
|
83
|
+
],
|
|
84
|
+
|
|
85
|
+
// CLI entry point
|
|
86
|
+
"bin": "./dist/cli.bundle.js",
|
|
87
|
+
|
|
76
88
|
// package entry points
|
|
77
89
|
// multiple entry points can be configured (".", "./module/", etc.)
|
|
78
90
|
//
|
|
@@ -92,27 +104,12 @@ The following fields are specific to this template:
|
|
|
92
104
|
}
|
|
93
105
|
},
|
|
94
106
|
|
|
95
|
-
// convenience alias for source-execution only
|
|
96
|
-
// NOT
|
|
97
|
-
// the .js extension is required in import statements (nodenext compliance)
|
|
107
|
+
// convenience alias for source-execution only
|
|
108
|
+
// does NOT survive transpilation or bundling
|
|
98
109
|
"imports": {
|
|
99
110
|
"#src/*.js": "./src/*.ts"
|
|
100
111
|
},
|
|
101
112
|
|
|
102
|
-
// CLI entry point
|
|
103
|
-
"bin": "./dist/cli.bundle.js",
|
|
104
|
-
|
|
105
|
-
// files to include in the published package
|
|
106
|
-
"files": [
|
|
107
|
-
"scripts/buildinfo.ts",
|
|
108
|
-
"scripts/build-bundle.ts",
|
|
109
|
-
"scripts/cdn-rewrite-map.json",
|
|
110
|
-
"CHANGELOG.md",
|
|
111
|
-
"buildinfo.txt",
|
|
112
|
-
"dist/",
|
|
113
|
-
"tests/"
|
|
114
|
-
],
|
|
115
|
-
|
|
116
113
|
"scripts": {
|
|
117
114
|
|
|
118
115
|
// ... ,
|
|
@@ -121,22 +118,22 @@ The following fields are specific to this template:
|
|
|
121
118
|
"clean:dist": "rm -rf dist/",
|
|
122
119
|
|
|
123
120
|
// removes .tsbuildinfo files generated by TypeScript's incremental build feature
|
|
124
|
-
"clean:tsbuildinfo": "rm -f
|
|
121
|
+
"clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
|
|
125
122
|
|
|
126
123
|
// convenience script to run the clean steps in sequence
|
|
127
|
-
"clean": "
|
|
124
|
+
"clean": "npm run clean:dist && npm run clean:tsbuildinfo",
|
|
128
125
|
|
|
129
126
|
// discovers and runs test files
|
|
130
|
-
"tests": "
|
|
127
|
+
"tests": "node --import tsx --test tests/**/*.test.ts",
|
|
131
128
|
|
|
132
129
|
// executed before build; generates buildinfo.txt
|
|
133
|
-
"prebuild": "
|
|
130
|
+
"prebuild": "npm run buildinfo",
|
|
134
131
|
|
|
135
132
|
// convenience script to run the build steps in sequence
|
|
136
|
-
"build": "
|
|
133
|
+
"build": "npm run build:bundle && npm run build:tsc && npm run build:cli-bundle",
|
|
137
134
|
|
|
138
135
|
// bundles the library into ESM and IIFE formats for distribution
|
|
139
|
-
"build:bundle": "
|
|
136
|
+
"build:bundle": "npm run scripts/build-bundle.ts",
|
|
140
137
|
|
|
141
138
|
// compiles the library to declaration files and ESM JavaScript in dist/
|
|
142
139
|
"build:tsc": "tsc --project tsconfig.build.json",
|
|
@@ -147,19 +144,15 @@ The following fields are specific to this template:
|
|
|
147
144
|
},
|
|
148
145
|
|
|
149
146
|
"devDependencies": {
|
|
150
|
-
"@types/bun": "latest",
|
|
151
147
|
"@types/node": "latest",
|
|
152
148
|
"esbuild": "latest",
|
|
149
|
+
"tsx": "latest",
|
|
153
150
|
"typescript": "^6.0.3"
|
|
154
151
|
}
|
|
155
152
|
|
|
156
153
|
}
|
|
157
154
|
```
|
|
158
155
|
|
|
159
|
-
It is highly recommended to include `tests/` in the `files` field. Note, that `tests/` is not included by default in the generated `package.json`.
|
|
160
|
-
|
|
161
|
-
`"@types/bun": "latest"` is required to run tests.
|
|
162
|
-
|
|
163
156
|
## Script `scripts/build-bundle.ts`
|
|
164
157
|
|
|
165
158
|
Bundles the library to ESM and IIFE formats using `esbuild`. 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.
|
|
@@ -180,7 +173,7 @@ Maps import specifiers to CDN URLs. During bundling, matching specifiers in sour
|
|
|
180
173
|
|
|
181
174
|
## `tsconfig.build.json`
|
|
182
175
|
|
|
183
|
-
`tsconfig.json`
|
|
176
|
+
`tsconfig.json` is intended for development only. `tsconfig.build.json` extends it with settings for compiling the source files for distribution.
|
|
184
177
|
|
|
185
178
|
See [`workspace` template 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.
|
|
186
179
|
|
|
@@ -348,20 +341,17 @@ const packageUrl = new URL('../', import.meta.url);
|
|
|
348
341
|
const assetsUrl = new URL('assets/<@SCOPE>/<LIB_NAME>/', packageUrl);
|
|
349
342
|
|
|
350
343
|
// for `--target browser` and `--target node` (isomorphic)
|
|
344
|
+
export { };
|
|
351
345
|
const assetUrl = new URL('<ASSET>', assetsUrl);
|
|
352
346
|
const asset = await fetch(assetUrl).then(response => response.body);
|
|
353
347
|
|
|
354
348
|
// for `--target node` only
|
|
355
|
-
import { readFile } from 'fs/promises';
|
|
356
|
-
import { fileURLToPath } from 'url';
|
|
349
|
+
import { readFile } from 'node:fs/promises';
|
|
357
350
|
const assetUrl = new URL('<ASSET>', assetsUrl);
|
|
358
|
-
const
|
|
359
|
-
const asset = await readFile(assetPath);
|
|
351
|
+
const asset = await readFile(assetUrl, 'utf-8');
|
|
360
352
|
```
|
|
361
353
|
|
|
362
|
-
The generated `./src/constants.ts` scaffolds the isomorphic approach and `./constants` is configured as an additional entry point in `package.json`
|
|
363
|
-
|
|
364
|
-
⚠️ Beware that `import.meta.url` is replaced by `document.currentScript.src` during bundling in IIFE format since it is available only under ESM (research "import.meta vs document.currentScript.src").
|
|
354
|
+
The generated `./src/constants.ts` scaffolds the isomorphic approach and `./constants` is configured as an additional entry point in `package.json` to preserve the `import.meta.url` usage in bundled scenarios:
|
|
365
355
|
|
|
366
356
|
```json
|
|
367
357
|
{
|
|
@@ -379,6 +369,8 @@ The generated `./src/constants.ts` scaffolds the isomorphic approach and `./cons
|
|
|
379
369
|
}
|
|
380
370
|
```
|
|
381
371
|
|
|
372
|
+
⚠️ Beware that `import.meta.url` is replaced by `document.currentScript.src` during bundling in IIFE format since it is available only under ESM (research "import.meta.url vs document.currentScript.src").
|
|
373
|
+
|
|
382
374
|
#### README statement for library consumers
|
|
383
375
|
|
|
384
376
|
```markdown
|
|
@@ -410,15 +402,16 @@ For CLI packages, add the following to `package.json`:
|
|
|
410
402
|
{
|
|
411
403
|
// ... ,
|
|
412
404
|
"bin": "./dist/cli.bundle.js",
|
|
405
|
+
// ... ,
|
|
413
406
|
"scripts": {
|
|
414
407
|
// ... ,
|
|
415
|
-
"build": "... &&
|
|
416
|
-
"build:cli-bundle": "
|
|
408
|
+
"build": "... && npm run build:cli-bundle",
|
|
409
|
+
"build:cli-bundle": "esbuild src/cli.ts --outdir=dist --entry-names=[dir]/[name].bundle --platform=node --format=esm --bundle --minify --sourcemap=external"
|
|
417
410
|
}
|
|
418
411
|
}
|
|
419
412
|
```
|
|
420
413
|
|
|
421
|
-
`src/cli.ts` must begin with a hashbang so the OS knows which interpreter to invoke when the binary is executed directly.
|
|
414
|
+
`src/cli.ts` must begin with a hashbang so the OS knows which interpreter to invoke when the binary is executed directly.
|
|
422
415
|
|
|
423
416
|
```typescript
|
|
424
417
|
#!/usr/bin/env node
|
|
@@ -429,16 +422,14 @@ If the package exports a CLI only and is not intended to be imported in other pa
|
|
|
429
422
|
# DevOps
|
|
430
423
|
|
|
431
424
|
```bash
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
bun run clean
|
|
436
|
-
bun run build
|
|
437
|
-
bun run tests
|
|
425
|
+
npm install
|
|
426
|
+
npm update
|
|
438
427
|
|
|
439
|
-
|
|
428
|
+
npm run clean
|
|
429
|
+
npm run build
|
|
430
|
+
npm run tests
|
|
440
431
|
|
|
441
|
-
|
|
432
|
+
npmx tsx dist/cli.bundle.js -- example/
|
|
442
433
|
```
|
|
443
434
|
|
|
444
435
|
## Change Management
|
|
@@ -447,17 +438,20 @@ bun run dist/cli.bundle.js -- example/
|
|
|
447
438
|
2. Make the changes and commit.
|
|
448
439
|
3. Bump the version in [`package.json`](package.json).
|
|
449
440
|
4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
|
|
450
|
-
5. Pull
|
|
441
|
+
5. Pull-request the branch.
|
|
451
442
|
6. Ensure package artifacts are current.
|
|
452
443
|
7. Publish.
|
|
453
444
|
|
|
454
445
|
## Publish
|
|
455
446
|
|
|
456
|
-
|
|
447
|
+
`~/.npmrc` or `.npmrc`:
|
|
457
448
|
|
|
458
|
-
```
|
|
459
|
-
|
|
449
|
+
```ini
|
|
450
|
+
@temir.ra:registry=https://registry.npmjs.org/
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
# registry.npmjs.org/
|
|
460
455
|
npm login
|
|
461
|
-
|
|
462
|
-
bun publish --registry https://registry.npmjs.org/ --access public
|
|
456
|
+
npm publish
|
|
463
457
|
```
|
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.11.0-pre.12+4148911
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{cpSync as a,readFileSync as g,renameSync as U,writeFileSync as d}from"node:fs";import{resolve as r}from"node:path";var n=new URL("../",import.meta.url),i=new URL("README.md",n),l=new URL("CHANGELOG.md",n),m=new URL("buildinfo.txt",n),u=new URL("dist/",n),p=new URL("template/",n);try{let t=process.argv[2];if(!t)throw new Error('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');let o=t.replace(/\\/g,"/"),e=r(process.cwd(),o);a(p,e,{recursive:!0}),a(l,r(e,"CHANGELOG-template.md")),a(m,r(e,"buildinfo-template.txt")),a(i,r(e,"README-template.md"));let c=r(e,"package.json"),s=JSON.parse(g(c,"utf-8"));s.name=o,d(c,JSON.stringify(s,null,2)),U(r(e,"gitignore"),r(e,".gitignore")),console.log(`Template has been successfully instantiated at '${e}' with package name '${o}'.`)}catch(t){let o=t instanceof Error?t:new Error(String(t));console.error("Error:",o.message),process.exit(1)}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/cli.ts", "../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\r\nimport { resolve } from 'node:path';\r\nimport {\r\n templateUrl,\r\n changelogUrl,\r\n buildinfoUrl,\r\n readmeUrl\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument)\r\n throw new Error('First argument must be the package name (e.g. \"my-package\" or \"@my-scope/my-package\").');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templateUrl, destinationPath, { recursive: true });\r\n cpSync(changelogUrl, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoUrl, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmeUrl, 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", "export const packageUrl: URL = new URL('../', import.meta.url);\r\n\r\nexport const readmeUrl: URL = new URL('README.md', packageUrl);\r\nexport const changelogUrl: URL = new URL('CHANGELOG.md', packageUrl);\r\nexport const buildinfoUrl: URL = new URL('buildinfo.txt', packageUrl);\r\nexport const distUrl: URL = new URL('dist/', packageUrl);\r\n\r\nexport const templateUrl: URL = new URL('template/', packageUrl);\r\n"],
|
|
5
|
+
"mappings": ";AAEA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,UAChE,OAAS,WAAAC,MAAe,YCHjB,IAAMC,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAEhDC,EAAiB,IAAI,IAAI,YAAaD,CAAU,EAChDE,EAAoB,IAAI,IAAI,eAAgBF,CAAU,EACtDG,EAAoB,IAAI,IAAI,gBAAiBH,CAAU,EACvDI,EAAe,IAAI,IAAI,QAASJ,CAAU,EAE1CK,EAAmB,IAAI,IAAI,YAAaL,CAAU,EDK/D,GAAI,CAEA,IAAMM,EAAsB,QAAQ,KAAK,CAAC,EAC1C,GAAI,CAACA,EACD,MAAM,IAAI,MAAM,wFAAwF,EAC5G,IAAMC,EAAcD,EAAoB,QAAQ,MAAO,GAAG,EAEpDE,EAAkBC,EAAQ,QAAQ,IAAI,EAAGF,CAAW,EAE1DG,EAAOC,EAAaH,EAAiB,CAAE,UAAW,EAAK,CAAC,EACxDE,EAAOE,EAAcH,EAAQD,EAAiB,uBAAuB,CAAC,EACtEE,EAAOG,EAAcJ,EAAQD,EAAiB,wBAAwB,CAAC,EACvEE,EAAOI,EAAWL,EAAQD,EAAiB,oBAAoB,CAAC,EAEhE,IAAMO,EAAkBN,EAAQD,EAAiB,cAAc,EACzDQ,EAAc,KAAK,MAAMC,EAAaF,EAAiB,OAAO,CAAC,EACrEC,EAAY,KAAOT,EACnBW,EAAcH,EAAiB,KAAK,UAAUC,EAAa,KAAM,CAAC,CAAC,EAEnEG,EAAWV,EAAQD,EAAiB,WAAW,EAAGC,EAAQD,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmDA,CAAe,wBAAwBD,CAAW,IAAI,CAEzH,OACOa,EAAO,CACV,IAAMC,EAAMD,aAAiB,MAAQA,EAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAUC,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC,CAClB",
|
|
6
|
+
"names": ["cpSync", "readFileSync", "renameSync", "writeFileSync", "resolve", "packageUrl", "readmeUrl", "changelogUrl", "buildinfoUrl", "distUrl", "templateUrl", "packageNameArgument", "packageName", "destinationPath", "resolve", "cpSync", "templateUrl", "changelogUrl", "buildinfoUrl", "readmeUrl", "packageJsonPath", "packageJson", "readFileSync", "writeFileSync", "renameSync", "error", "err"]
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@temir.ra/create-ts-lib",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A template for a distributable TypeScript library package.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"type": "module",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"clean:
|
|
37
|
-
"clean": "
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"build
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@temir.ra/create-ts-lib",
|
|
3
|
+
"version": "0.11.0-pre.12",
|
|
4
|
+
"description": "A template for a distributable TypeScript library package.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"keywords": [
|
|
7
|
+
"typescript",
|
|
8
|
+
"template",
|
|
9
|
+
"library"
|
|
10
|
+
],
|
|
11
|
+
"author": "temir.ra",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://git.chimps.quest/trs/create-ts-lib.git"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"files": [
|
|
19
|
+
"scripts/buildinfo.ts",
|
|
20
|
+
"scripts/build-bundle.ts",
|
|
21
|
+
"scripts/cdn-rewrite-map.json",
|
|
22
|
+
"CHANGELOG.md",
|
|
23
|
+
"buildinfo.txt",
|
|
24
|
+
"dist/",
|
|
25
|
+
"tests/",
|
|
26
|
+
"template/"
|
|
27
|
+
],
|
|
28
|
+
"bin": "./dist/cli.bundle.js",
|
|
29
|
+
"imports": {
|
|
30
|
+
"#src/*.js": "./src/*.ts"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"reinstall": "rm -rf node_modules && rm -f package-lock.json bun.lock yarn.lock pnpm-lock.yaml && npm install",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"buildinfo": "tsx scripts/buildinfo.ts",
|
|
36
|
+
"clean:dist": "rm -rf dist/",
|
|
37
|
+
"clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
|
|
38
|
+
"clean": "npm run clean:dist && npm run clean:tsbuildinfo",
|
|
39
|
+
"tests": "node --import tsx --test tests/**/*.test.ts",
|
|
40
|
+
"prebuild": "npm run buildinfo",
|
|
41
|
+
"build": "npm run build:cli-bundle",
|
|
42
|
+
"build:cli-bundle": "esbuild src/cli.ts --outdir=dist --entry-names=[dir]/[name].bundle --platform=node --format=esm --bundle --minify --sourcemap=external"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "latest",
|
|
46
|
+
"esbuild": "latest",
|
|
47
|
+
"tsx": "latest",
|
|
48
|
+
"typescript": "^6.0.3"
|
|
49
|
+
}
|
|
48
50
|
}
|
package/template/README.md
CHANGED
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
3. [DevOps](#devops)
|
|
10
10
|
1. [Change Management](#change-management)
|
|
11
11
|
2. [Publish](#publish)
|
|
12
|
-
1. [npmjs.org](#npmjsorg)
|
|
13
|
-
2. [Custom registry](#custom-registry)
|
|
14
12
|
|
|
15
13
|
# Quick Start
|
|
16
14
|
|
|
@@ -23,16 +21,14 @@
|
|
|
23
21
|
# DevOps
|
|
24
22
|
|
|
25
23
|
```bash
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
npm install
|
|
25
|
+
npm update
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
bun run build
|
|
31
|
-
bun run tests
|
|
27
|
+
npm run dev
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
npm run clean
|
|
30
|
+
npm run build
|
|
31
|
+
npm run tests
|
|
36
32
|
```
|
|
37
33
|
|
|
38
34
|
## Change Management
|
|
@@ -41,51 +37,42 @@ bun run --watch scripts/dev.ts
|
|
|
41
37
|
2. Make the changes and commit.
|
|
42
38
|
3. Bump the version in [`package.json`](package.json).
|
|
43
39
|
4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
|
|
44
|
-
5. Pull
|
|
40
|
+
5. Pull-request the branch.
|
|
45
41
|
6. Ensure package artifacts are current.
|
|
46
42
|
7. Publish.
|
|
47
43
|
|
|
48
44
|
## Publish
|
|
49
45
|
|
|
50
|
-
See the following sources to configure the target registry and authentication.
|
|
51
|
-
|
|
52
|
-
- [Configuring npm - `npmrc`](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc)
|
|
53
|
-
- [Bun package manager - `install.registry`](https://bun.com/docs/runtime/bunfig#install-scopes)
|
|
54
|
-
|
|
55
|
-
⚠️ Package Scope and the authentication for the target registry must be aligned.
|
|
56
|
-
|
|
57
|
-
### `npmjs.org`
|
|
58
|
-
|
|
59
|
-
Publish to the public npm registry.
|
|
60
|
-
|
|
61
|
-
```powershell
|
|
62
|
-
# authenticate
|
|
63
|
-
npm login
|
|
64
|
-
# publish
|
|
65
|
-
bun publish --registry https://registry.npmjs.org/ --access public
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Custom registry
|
|
69
|
-
|
|
70
|
-
Publish to a custom registry.
|
|
71
|
-
|
|
72
46
|
```bash
|
|
73
47
|
# placeholder:
|
|
74
48
|
# <SCOPE_WITHOUT_AT: <SCOPE_WITHOUT_AT>
|
|
75
|
-
# <
|
|
76
|
-
|
|
49
|
+
# <REGISTRY_ORIGIN_AND_PATH: <REGISTRY_ORIGIN_AND_PATH>
|
|
50
|
+
# e.g.
|
|
51
|
+
# registry.npmjs.org/
|
|
52
|
+
# forgejo.example.com/api/packages/<SCOPE_WITHOUT_AT>/npm/
|
|
53
|
+
# <REGISTRY_AUTH_TOKEN_ENV_VAR: <REGISTRY_AUTH_TOKEN_ENV_VAR>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`~/.npmrc` or `.npmrc`:
|
|
57
|
+
|
|
58
|
+
```ini
|
|
59
|
+
@<SCOPE_WITHOUT_AT>:registry=https://<REGISTRY_ORIGIN_AND_PATH>
|
|
60
|
+
//<REGISTRY_ORIGIN_AND_PATH>:_authToken=${<REGISTRY_AUTH_TOKEN_ENV_VAR>}
|
|
77
61
|
```
|
|
78
62
|
|
|
79
63
|
`~/.bunfig.toml` or `bunfig.toml`:
|
|
80
64
|
|
|
81
65
|
```toml
|
|
82
66
|
[install.scopes]
|
|
83
|
-
"<SCOPE_WITHOUT_AT>" = { url = "
|
|
67
|
+
"<SCOPE_WITHOUT_AT>" = { url = "https://<REGISTRY_ORIGIN_AND_PATH>", token = "$<REGISTRY_AUTH_TOKEN_ENV_VAR>" }
|
|
84
68
|
```
|
|
85
69
|
|
|
86
|
-
```
|
|
87
|
-
#
|
|
88
|
-
|
|
89
|
-
#
|
|
90
|
-
|
|
70
|
+
```bash
|
|
71
|
+
# registry.npmjs.org/
|
|
72
|
+
npm login
|
|
73
|
+
# or custom registry
|
|
74
|
+
export <REGISTRY_AUTH_TOKEN_ENV_VAR>=<AUTH_TOKEN>
|
|
75
|
+
# or
|
|
76
|
+
$env:<REGISTRY_AUTH_TOKEN_ENV_VAR> = "<AUTH_TOKEN>"
|
|
77
|
+
npm publish
|
|
91
78
|
```
|
package/template/package.json
CHANGED
|
@@ -2,17 +2,26 @@
|
|
|
2
2
|
"name": "",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"license": "",
|
|
5
|
+
"private": false,
|
|
7
6
|
"keywords": [
|
|
8
7
|
"typescript"
|
|
9
8
|
],
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "",
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
13
|
"url": ""
|
|
13
14
|
},
|
|
14
|
-
"private": false,
|
|
15
15
|
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"scripts/buildinfo.ts",
|
|
18
|
+
"scripts/build-bundle.ts",
|
|
19
|
+
"scripts/cdn-rewrite-map.json",
|
|
20
|
+
"CHANGELOG.md",
|
|
21
|
+
"buildinfo.txt",
|
|
22
|
+
"dist/",
|
|
23
|
+
"tests/"
|
|
24
|
+
],
|
|
16
25
|
"exports": {
|
|
17
26
|
".": {
|
|
18
27
|
"entrypoint": "./src/index.ts",
|
|
@@ -30,30 +39,24 @@
|
|
|
30
39
|
"imports": {
|
|
31
40
|
"#src/*.js": "./src/*.ts"
|
|
32
41
|
},
|
|
33
|
-
"files": [
|
|
34
|
-
"scripts/buildinfo.ts",
|
|
35
|
-
"scripts/build-bundle.ts",
|
|
36
|
-
"scripts/cdn-rewrite-map.json",
|
|
37
|
-
"CHANGELOG.md",
|
|
38
|
-
"buildinfo.txt",
|
|
39
|
-
"dist/"
|
|
40
|
-
],
|
|
41
42
|
"scripts": {
|
|
42
|
-
"reinstall": "rm -rf node_modules && rm -f bun.lock
|
|
43
|
+
"reinstall": "rm -rf node_modules && rm -f package-lock.json bun.lock yarn.lock pnpm-lock.yaml && npm install",
|
|
43
44
|
"typecheck": "tsc --noEmit",
|
|
44
|
-
"buildinfo": "
|
|
45
|
+
"buildinfo": "tsx scripts/buildinfo.ts",
|
|
46
|
+
"dev": "tsx --watch scripts/dev.ts",
|
|
45
47
|
"clean:dist": "rm -rf dist/",
|
|
46
|
-
"clean:tsbuildinfo": "rm -f
|
|
47
|
-
"clean": "
|
|
48
|
-
"tests": "
|
|
49
|
-
"prebuild": "
|
|
50
|
-
"build": "
|
|
51
|
-
"build:bundle": "
|
|
48
|
+
"clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
|
|
49
|
+
"clean": "npm run clean:dist && npm run clean:tsbuildinfo",
|
|
50
|
+
"tests": "node --import tsx --test tests/**/*.test.ts",
|
|
51
|
+
"prebuild": "npm run buildinfo",
|
|
52
|
+
"build": "npm run build:bundle && npm run build:tsc",
|
|
53
|
+
"build:bundle": "tsx scripts/build-bundle.ts",
|
|
52
54
|
"build:tsc": "tsc --project tsconfig.build.json"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
57
|
"@types/node": "latest",
|
|
56
58
|
"esbuild": "latest",
|
|
59
|
+
"tsx": "latest",
|
|
57
60
|
"typescript": "^6.0.3"
|
|
58
61
|
}
|
|
59
62
|
}
|
package/template/scripts/dev.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export const packageUrl: URL = new URL('../', import.meta.url);
|
|
2
|
+
|
|
3
|
+
export const readmeUrl: URL = new URL('README.md', packageUrl);
|
|
4
|
+
export const changelogUrl: URL = new URL('CHANGELOG.md', packageUrl);
|
|
2
5
|
export const buildinfoUrl: URL = new URL('buildinfo.txt', packageUrl);
|
|
3
6
|
export const distUrl: URL = new URL('dist/', packageUrl);
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { describe, it } from 'node:test';
|
|
2
2
|
import assert from 'node:assert';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import {
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { buildinfoUrl, packageUrl } from '#src/constants.js';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
const buildinfoUrl = new URL('../buildinfo.txt', import.meta.url);
|
|
8
|
-
|
|
9
7
|
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
|
10
8
|
// Captures: [1]=major, [2]=minor, [3]=patch, [4]=pre-release, [5]=build-metadata
|
|
11
9
|
const SEMVER_REGEX =
|
|
12
10
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
13
11
|
|
|
14
|
-
function readBuildinfo(): string {
|
|
15
|
-
return readFileSync(fileURLToPath(buildinfoUrl), 'utf-8').trim();
|
|
16
|
-
}
|
|
17
12
|
|
|
18
13
|
describe('buildinfo.txt', () => {
|
|
19
14
|
|
|
20
|
-
it('MUST
|
|
21
|
-
assert.
|
|
15
|
+
it('MUST exist at the specified location', async () => {
|
|
16
|
+
assert.ok(existsSync(buildinfoUrl));
|
|
17
|
+
assert.ok(!existsSync(new URL('wrong.txt', packageUrl)));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('MUST contain a valid semver string', async () => {
|
|
21
|
+
const buildinfo = readFileSync(buildinfoUrl, 'utf-8');
|
|
22
|
+
assert.match(buildinfo, SEMVER_REGEX);
|
|
23
|
+
assert.doesNotMatch('version zwölf', SEMVER_REGEX);
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
});
|
package/template/tsconfig.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { buildinfoUrl, packageUrl } from '#src/constants.js';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
|
8
|
+
// Captures: [1]=major, [2]=minor, [3]=patch, [4]=pre-release, [5]=build-metadata
|
|
9
|
+
const SEMVER_REGEX =
|
|
10
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
describe('buildinfo.txt', () => {
|
|
14
|
+
|
|
15
|
+
it('MUST exist at the specified location', async () => {
|
|
16
|
+
assert.ok(existsSync(buildinfoUrl));
|
|
17
|
+
assert.ok(!existsSync(new URL('wrong.txt', packageUrl)));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('MUST contain a valid semver string', async () => {
|
|
21
|
+
const buildinfo = readFileSync(buildinfoUrl, 'utf-8');
|
|
22
|
+
assert.match(buildinfo, SEMVER_REGEX);
|
|
23
|
+
assert.doesNotMatch('version zwölf', SEMVER_REGEX);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
});
|