@temir.ra/create-ts-lib 0.10.1 → 0.11.0-pre.8
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 +10 -0
- package/README.md +48 -72
- package/buildinfo.txt +1 -1
- package/dist/cli.bundle.js +1 -1
- package/dist/cli.bundle.js.map +3 -3
- package/package.json +49 -47
- package/template/README.md +18 -46
- 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,15 @@
|
|
|
1
1
|
# Version 0
|
|
2
2
|
|
|
3
|
+
## 0.11.0-pre.6
|
|
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. Simplified the Publish section in the generated README, as the registry configuration steps are now covered in the `workspace` template README.
|
|
12
|
+
|
|
3
13
|
## 0.10.1
|
|
4
14
|
|
|
5
15
|
1. Fixed missing build output files.
|
package/README.md
CHANGED
|
@@ -6,19 +6,6 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
|
|
|
6
6
|
|
|
7
7
|
1. [Quick Start](#quick-start)
|
|
8
8
|
2. [Documentation](#documentation)
|
|
9
|
-
1. [`package.json`](#packagejson)
|
|
10
|
-
2. [Script `scripts/build-bundle.ts`](#script-scriptsbuild-bundlets)
|
|
11
|
-
1. [CDN Map `scripts/cdn-rewrite-map.json`](#cdn-map-scriptscdn-rewrite-mapjson)
|
|
12
|
-
3. [`tsconfig.build.json`](#tsconfigbuildjson)
|
|
13
|
-
4. [Asset Resolution](#asset-resolution)
|
|
14
|
-
1. [Externalized - loaded from CDN or `node_modules/`](#externalized---loaded-from-cdn-or-node_modules)
|
|
15
|
-
2. [Bundled - absorbed into the consumer's output](#bundled---absorbed-into-the-consumers-output)
|
|
16
|
-
3. [Contract](#contract)
|
|
17
|
-
1. [Scoped assets directory convention](#scoped-assets-directory-convention)
|
|
18
|
-
2. [Accessing assets](#accessing-assets)
|
|
19
|
-
3. [README statement for library consumers](#readme-statement-for-library-consumers)
|
|
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)
|
|
22
9
|
3. [DevOps](#devops)
|
|
23
10
|
1. [Change Management](#change-management)
|
|
24
11
|
2. [Publish](#publish)
|
|
@@ -27,13 +14,9 @@ A template for TypeScript libraries distributed via npm-compatible registries. P
|
|
|
27
14
|
|
|
28
15
|
```bash
|
|
29
16
|
# placeholder:
|
|
30
|
-
# <NEW_PACKAGE: <NEW_PACKAGE>
|
|
31
17
|
# <TEMPLATE_PACKAGE_NAME: @temir.ra/create-ts-lib
|
|
32
18
|
# <TEMPLATE_NAME: @temir.ra/ts-lib
|
|
33
19
|
|
|
34
|
-
mkdir -p <NEW_PACKAGE>
|
|
35
|
-
cd <NEW_PACKAGE>
|
|
36
|
-
|
|
37
20
|
# print the latest version
|
|
38
21
|
bun info "@temir.ra/create-ts-lib" version
|
|
39
22
|
|
|
@@ -52,7 +35,7 @@ The following sections explain the configurations and conventions baked into the
|
|
|
52
35
|
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
36
|
|
|
54
37
|
- **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).
|
|
38
|
+
- **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
39
|
|
|
57
40
|
Both strategies can be combined.
|
|
58
41
|
|
|
@@ -70,9 +53,25 @@ The following fields are specific to this template:
|
|
|
70
53
|
// the package is anticipated to be published
|
|
71
54
|
"private": false,
|
|
72
55
|
|
|
56
|
+
// ... ,
|
|
57
|
+
|
|
73
58
|
// treats all .js files as ES modules; use .cjs extension for CommonJS files
|
|
74
59
|
"type": "module",
|
|
75
60
|
|
|
61
|
+
// files to include in the published package
|
|
62
|
+
"files": [
|
|
63
|
+
"scripts/buildinfo.ts",
|
|
64
|
+
"scripts/build-bundle.ts",
|
|
65
|
+
"scripts/cdn-rewrite-map.json",
|
|
66
|
+
"CHANGELOG.md",
|
|
67
|
+
"buildinfo.txt",
|
|
68
|
+
"dist/",
|
|
69
|
+
"tests/"
|
|
70
|
+
],
|
|
71
|
+
|
|
72
|
+
// CLI entry point
|
|
73
|
+
"bin": "./dist/cli.bundle.js",
|
|
74
|
+
|
|
76
75
|
// package entry points
|
|
77
76
|
// multiple entry points can be configured (".", "./module/", etc.)
|
|
78
77
|
//
|
|
@@ -92,27 +91,12 @@ The following fields are specific to this template:
|
|
|
92
91
|
}
|
|
93
92
|
},
|
|
94
93
|
|
|
95
|
-
// convenience alias for source-execution only
|
|
96
|
-
// NOT
|
|
97
|
-
// the .js extension is required in import statements (nodenext compliance)
|
|
94
|
+
// convenience alias for source-execution only
|
|
95
|
+
// does NOT survive transpilation or bundling
|
|
98
96
|
"imports": {
|
|
99
97
|
"#src/*.js": "./src/*.ts"
|
|
100
98
|
},
|
|
101
99
|
|
|
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
100
|
"scripts": {
|
|
117
101
|
|
|
118
102
|
// ... ,
|
|
@@ -121,22 +105,22 @@ The following fields are specific to this template:
|
|
|
121
105
|
"clean:dist": "rm -rf dist/",
|
|
122
106
|
|
|
123
107
|
// removes .tsbuildinfo files generated by TypeScript's incremental build feature
|
|
124
|
-
"clean:tsbuildinfo": "rm -f
|
|
108
|
+
"clean:tsbuildinfo": "rm -f tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo",
|
|
125
109
|
|
|
126
110
|
// convenience script to run the clean steps in sequence
|
|
127
|
-
"clean": "
|
|
111
|
+
"clean": "npm run clean:dist && npm run clean:tsbuildinfo",
|
|
128
112
|
|
|
129
113
|
// discovers and runs test files
|
|
130
|
-
"tests": "
|
|
114
|
+
"tests": "node --import tsx --test tests/**/*.test.ts",
|
|
131
115
|
|
|
132
116
|
// executed before build; generates buildinfo.txt
|
|
133
|
-
"prebuild": "
|
|
117
|
+
"prebuild": "npm run buildinfo",
|
|
134
118
|
|
|
135
119
|
// convenience script to run the build steps in sequence
|
|
136
|
-
"build": "
|
|
120
|
+
"build": "npm run build:bundle && npm run build:tsc && npm run build:cli-bundle",
|
|
137
121
|
|
|
138
122
|
// bundles the library into ESM and IIFE formats for distribution
|
|
139
|
-
"build:bundle": "
|
|
123
|
+
"build:bundle": "npm run scripts/build-bundle.ts",
|
|
140
124
|
|
|
141
125
|
// compiles the library to declaration files and ESM JavaScript in dist/
|
|
142
126
|
"build:tsc": "tsc --project tsconfig.build.json",
|
|
@@ -147,19 +131,15 @@ The following fields are specific to this template:
|
|
|
147
131
|
},
|
|
148
132
|
|
|
149
133
|
"devDependencies": {
|
|
150
|
-
"@types/bun": "latest",
|
|
151
134
|
"@types/node": "latest",
|
|
152
135
|
"esbuild": "latest",
|
|
136
|
+
"tsx": "latest",
|
|
153
137
|
"typescript": "^6.0.3"
|
|
154
138
|
}
|
|
155
139
|
|
|
156
140
|
}
|
|
157
141
|
```
|
|
158
142
|
|
|
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
143
|
## Script `scripts/build-bundle.ts`
|
|
164
144
|
|
|
165
145
|
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 +160,7 @@ Maps import specifiers to CDN URLs. During bundling, matching specifiers in sour
|
|
|
180
160
|
|
|
181
161
|
## `tsconfig.build.json`
|
|
182
162
|
|
|
183
|
-
`tsconfig.json`
|
|
163
|
+
`tsconfig.json` is intended for development only. `tsconfig.build.json` extends it with settings for compiling the source files for distribution.
|
|
184
164
|
|
|
185
165
|
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
166
|
|
|
@@ -348,20 +328,17 @@ const packageUrl = new URL('../', import.meta.url);
|
|
|
348
328
|
const assetsUrl = new URL('assets/<@SCOPE>/<LIB_NAME>/', packageUrl);
|
|
349
329
|
|
|
350
330
|
// for `--target browser` and `--target node` (isomorphic)
|
|
331
|
+
export { };
|
|
351
332
|
const assetUrl = new URL('<ASSET>', assetsUrl);
|
|
352
333
|
const asset = await fetch(assetUrl).then(response => response.body);
|
|
353
334
|
|
|
354
335
|
// for `--target node` only
|
|
355
|
-
import { readFile } from 'fs/promises';
|
|
356
|
-
import { fileURLToPath } from 'url';
|
|
336
|
+
import { readFile } from 'node:fs/promises';
|
|
357
337
|
const assetUrl = new URL('<ASSET>', assetsUrl);
|
|
358
|
-
const
|
|
359
|
-
const asset = await readFile(assetPath);
|
|
338
|
+
const asset = await readFile(assetUrl, 'utf-8');
|
|
360
339
|
```
|
|
361
340
|
|
|
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").
|
|
341
|
+
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
342
|
|
|
366
343
|
```json
|
|
367
344
|
{
|
|
@@ -379,6 +356,8 @@ The generated `./src/constants.ts` scaffolds the isomorphic approach and `./cons
|
|
|
379
356
|
}
|
|
380
357
|
```
|
|
381
358
|
|
|
359
|
+
⚠️ 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").
|
|
360
|
+
|
|
382
361
|
#### README statement for library consumers
|
|
383
362
|
|
|
384
363
|
```markdown
|
|
@@ -410,15 +389,16 @@ For CLI packages, add the following to `package.json`:
|
|
|
410
389
|
{
|
|
411
390
|
// ... ,
|
|
412
391
|
"bin": "./dist/cli.bundle.js",
|
|
392
|
+
// ... ,
|
|
413
393
|
"scripts": {
|
|
414
394
|
// ... ,
|
|
415
|
-
"build": "... &&
|
|
416
|
-
"build:cli-bundle": "
|
|
395
|
+
"build": "... && npm run build:cli-bundle",
|
|
396
|
+
"build:cli-bundle": "esbuild src/cli.ts --outdir=dist --entry-names=[dir]/[name].bundle --platform=node --format=esm --bundle --minify --sourcemap=external"
|
|
417
397
|
}
|
|
418
398
|
}
|
|
419
399
|
```
|
|
420
400
|
|
|
421
|
-
`src/cli.ts` must begin with a hashbang so the OS knows which interpreter to invoke when the binary is executed directly.
|
|
401
|
+
`src/cli.ts` must begin with a hashbang so the OS knows which interpreter to invoke when the binary is executed directly.
|
|
422
402
|
|
|
423
403
|
```typescript
|
|
424
404
|
#!/usr/bin/env node
|
|
@@ -429,16 +409,14 @@ If the package exports a CLI only and is not intended to be imported in other pa
|
|
|
429
409
|
# DevOps
|
|
430
410
|
|
|
431
411
|
```bash
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
bun run clean
|
|
436
|
-
bun run build
|
|
437
|
-
bun run tests
|
|
412
|
+
npm update
|
|
413
|
+
npm install
|
|
438
414
|
|
|
439
|
-
|
|
415
|
+
npm run clean
|
|
416
|
+
npm run build
|
|
417
|
+
npm run tests
|
|
440
418
|
|
|
441
|
-
|
|
419
|
+
npmx tsx dist/cli.bundle.js -- example/
|
|
442
420
|
```
|
|
443
421
|
|
|
444
422
|
## Change Management
|
|
@@ -447,17 +425,15 @@ bun run dist/cli.bundle.js -- example/
|
|
|
447
425
|
2. Make the changes and commit.
|
|
448
426
|
3. Bump the version in [`package.json`](package.json).
|
|
449
427
|
4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
|
|
450
|
-
5. Pull
|
|
428
|
+
5. Pull-request the branch.
|
|
451
429
|
6. Ensure package artifacts are current.
|
|
452
430
|
7. Publish.
|
|
453
431
|
|
|
454
432
|
## Publish
|
|
455
433
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
```powershell
|
|
459
|
-
# authenticate
|
|
434
|
+
```bash
|
|
435
|
+
# registry.npmjs.org/
|
|
460
436
|
npm login
|
|
461
|
-
|
|
462
|
-
|
|
437
|
+
|
|
438
|
+
npm publish --registry https://registry.npmjs.org/
|
|
463
439
|
```
|
package/buildinfo.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.11.0-pre.8+3ebf4d9
|
package/dist/cli.bundle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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("
|
|
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)}
|
package/dist/cli.bundle.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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\nexport const
|
|
5
|
-
"mappings": ";AAEA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,UAChE,OAAS,WAAAC,MAAe,YCHjB,IAAMC,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,
|
|
6
|
-
"names": ["cpSync", "readFileSync", "renameSync", "writeFileSync", "resolve", "packageUrl", "
|
|
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
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.8",
|
|
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": "shx rm -rf node_modules && shx 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": "shx rm -rf dist/",
|
|
37
|
+
"clean:tsbuildinfo": "shx 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 update
|
|
25
|
+
npm install
|
|
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,27 @@ 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
|
-
|
|
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.
|
|
46
|
+
Configure the scope registry as described in the [`workspace` template README](https://git.chimps.quest/trs/create-workspace#scope-registry).
|
|
71
47
|
|
|
72
48
|
```bash
|
|
73
49
|
# placeholder:
|
|
74
|
-
# <
|
|
75
|
-
# <REGISTRY_URL: <REGISTRY_URL>
|
|
76
|
-
# <BUN_PUBLISH_AUTH_TOKEN: <BUN_PUBLISH_AUTH_TOKEN>
|
|
50
|
+
# <REGISTRY_AUTH_TOKEN_ENV_VAR: <REGISTRY_AUTH_TOKEN_ENV_VAR>
|
|
77
51
|
```
|
|
78
52
|
|
|
79
|
-
|
|
53
|
+
Authenticate with the registry:
|
|
80
54
|
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
# publish
|
|
90
|
-
bun publish
|
|
55
|
+
```bash
|
|
56
|
+
# registry.npmjs.org/
|
|
57
|
+
npm login
|
|
58
|
+
# or custom registry
|
|
59
|
+
export <REGISTRY_AUTH_TOKEN_ENV_VAR>=<AUTH_TOKEN>
|
|
60
|
+
# or
|
|
61
|
+
$env:<REGISTRY_AUTH_TOKEN_ENV_VAR> = "<AUTH_TOKEN>"
|
|
62
|
+
npm publish
|
|
91
63
|
```
|
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
|
+
});
|