@temir.ra/create-ts-lib 0.10.0 → 0.11.0-pre.7
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 +2 -186
- package/README.md +45 -69
- 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 +22 -45
- 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,189 +1,5 @@
|
|
|
1
1
|
# Version 0
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.0.0
|
|
4
4
|
|
|
5
|
-
1.
|
|
6
|
-
2. Switched to `node:test` for tests.
|
|
7
|
-
3. Synced with `template@0.3.0-pre.3` template.
|
|
8
|
-
|
|
9
|
-
## 0.9.1
|
|
10
|
-
|
|
11
|
-
1. Updated from `template@0.2.1` template.
|
|
12
|
-
|
|
13
|
-
## 0.9.0
|
|
14
|
-
|
|
15
|
-
1. Switched to `esbuild` for bundling.
|
|
16
|
-
2. Switched to `@types/node` for type definitions.
|
|
17
|
-
3. Updated documentation to reflect the `esbuild` and `@types/node` changes.
|
|
18
|
-
4. Synced with `template@0.2.0-pre.5` template.
|
|
19
|
-
|
|
20
|
-
## 0.8.4
|
|
21
|
-
|
|
22
|
-
1. Fixed CDN rewrite plugin filter.
|
|
23
|
-
|
|
24
|
-
## 0.8.3
|
|
25
|
-
|
|
26
|
-
1. Updated buildinfo test wording to align with qualification strategies.
|
|
27
|
-
2. Fixed CDN rewrite resolution.
|
|
28
|
-
3. Added `--omit-iife` flag to optionally skip generating the IIFE bundle.
|
|
29
|
-
4. Synced with `template` template.
|
|
30
|
-
|
|
31
|
-
## 0.8.2
|
|
32
|
-
|
|
33
|
-
1. Updated from `template@0.1.9` template.
|
|
34
|
-
|
|
35
|
-
## 0.8.1
|
|
36
|
-
|
|
37
|
-
1. Added `DOM` to the `lib` array in the generated `tsconfig.json`.
|
|
38
|
-
|
|
39
|
-
## 0.8.0
|
|
40
|
-
|
|
41
|
-
1. Updated wording in the Publish section of the generated README.
|
|
42
|
-
2. `build:tsc` step is now generated per default.
|
|
43
|
-
3. Added `./constants` entrypoint to `package.json`.
|
|
44
|
-
|
|
45
|
-
## 0.7.6
|
|
46
|
-
|
|
47
|
-
1. Updated `typescript` to `6.0.3`.
|
|
48
|
-
2. Cleaned up minor `README.md` inconsistencies.
|
|
49
|
-
3. Aligned wording with [`RFC 2119`](https://datatracker.ietf.org/doc/html/rfc2119).
|
|
50
|
-
4. Updated files from `template` template.
|
|
51
|
-
|
|
52
|
-
## 0.7.5
|
|
53
|
-
|
|
54
|
-
1. Updated files from `@temir.ra/template@0.1.6` template.
|
|
55
|
-
|
|
56
|
-
## 0.7.4
|
|
57
|
-
|
|
58
|
-
1. Updated `keywords` in `template/package.json`.
|
|
59
|
-
2. Restored docs for `build*` and `tests` `package.json` scripts in `README.md`.
|
|
60
|
-
3. Reduced `scripts/dev.ts` section to a DevOps command.
|
|
61
|
-
4. Added clarification on the `files` field recommendation for `tests/` in the README.
|
|
62
|
-
5. Updated from `@temir.ra/template@0.1.5` template.
|
|
63
|
-
|
|
64
|
-
## 0.7.3
|
|
65
|
-
|
|
66
|
-
1. Updated from `@temir.ra/template@0.1.4` template.
|
|
67
|
-
|
|
68
|
-
## 0.7.2
|
|
69
|
-
|
|
70
|
-
1. Cleaned up `*-template.*` files from the template directory.
|
|
71
|
-
|
|
72
|
-
## 0.7.1
|
|
73
|
-
|
|
74
|
-
1. Updated `template/` files from `@temir.ra/workspace@0.4.1` template.
|
|
75
|
-
|
|
76
|
-
## 0.7.0
|
|
77
|
-
|
|
78
|
-
1. Updated `.gitignore`: added `bun.lock`, `buildinfo-template.txt`, `CHANGELOG-template.md`, `README-template.md`; replaced nested `template/.gitignore` with `template/gitignore` to prevent template files from being excluded during distribution.
|
|
79
|
-
2. Removed `CLAUDE.md`, `AGENTS.md`, and `src/dev.ts` from root and template.
|
|
80
|
-
3. Overhauled the generated `package.json`: added `private: false`; removed `sideEffects: false`; added build scripts to published `files`; updated `clean:tsbuildinfo` to `rm -f *.tsbuildinfo || true`; renamed `build:lib-bundle` to `build:bundle`; removed `build:lib` and `dev` scripts; added `reinstall` script; bumped typescript to `^6.0.2`.
|
|
81
|
-
4. Updated the generated `tsconfig.json`: changed `target` to `ESNext`; removed `DOM` from `lib`; added `types: ["bun"]`.
|
|
82
|
-
5. Removed generated `tsconfig.build.json`; TSC compilation is now opt-in and documented in `README.md`.
|
|
83
|
-
6. Renamed `scripts/build-lib-bundle.ts` to `scripts/build-bundle.ts` in root and template; updated to produce ESM and IIFE browser bundles; added to published `files`; updated CDN rewrite plugin filter.
|
|
84
|
-
7. Extracted path constants from `src/cli.ts` to `src/constants.ts`; CLI now copies `README.md` as `README-template.md` to generated projects; improved error message for missing package name argument; moved `template/src/dev.ts` to `template/scripts/dev.ts`.
|
|
85
|
-
8. Updated `scripts/buildinfo.ts` in root and template: reads version from `package.json` instead of `npm_package_version` env var; handles pre-existing `+` in version string.
|
|
86
|
-
9. Refactored `template/tests/buildinfo.test.ts` to use a proper semver regex.
|
|
87
|
-
10. Overhauled `README.md`: new documentation structure with build strategies overview, `package.json` and `tsconfig.json` sections referencing `create-workspace`, opt-in TSC Compilation section, `bin` field documentation, `scripts/dev.ts` section; removed `CLAUDE.md`/`AGENTS.md` section.
|
|
88
|
-
11. Updated from `@temir.ra/template@0.1.3` template.
|
|
89
|
-
|
|
90
|
-
## 0.6.3
|
|
91
|
-
|
|
92
|
-
1. Cleaned up dormant package scripts.
|
|
93
|
-
2. Cleaned up minor `README.md` inconsistencies.
|
|
94
|
-
|
|
95
|
-
## 0.6.2
|
|
96
|
-
|
|
97
|
-
1. Updated `clean:tsbuildinfo` script to remove both `tsconfig.tsbuildinfo` and `tsconfig.build.tsbuildinfo`.
|
|
98
|
-
|
|
99
|
-
## 0.6.1
|
|
100
|
-
|
|
101
|
-
1. Cleaned up dormant imports.
|
|
102
|
-
2. Cleaned up / updated minor `README.md` inconsistencies.
|
|
103
|
-
3. Updated placeholders in `README.md` in the **Asset resolution** section.
|
|
104
|
-
4. Removed **Asset resolution** section from the generated `README.md`, as the operational passage is given in the template `README.md`.
|
|
105
|
-
5. Removed **AI Assistant Context** section from the `README.md` files.
|
|
106
|
-
7. Cleaned up **Publish** section in the `README.md`.
|
|
107
|
-
|
|
108
|
-
## 0.6.0
|
|
109
|
-
|
|
110
|
-
1. Updated documentation and configs to TypeScript 6.
|
|
111
|
-
|
|
112
|
-
## 0.5.0
|
|
113
|
-
|
|
114
|
-
1. Changed `buildinfo.txt` generation and testing to align with [https://semver.org](https://semver.org).
|
|
115
|
-
|
|
116
|
-
## 0.4.1
|
|
117
|
-
|
|
118
|
-
1. Fixed `destinationPath` resolution in `cli.ts` to use the full resolved path instead of just the basename.
|
|
119
|
-
|
|
120
|
-
## 0.4.0
|
|
121
|
-
|
|
122
|
-
1. Added support for scoped package names in the CLI argument parsing and asset resolution.
|
|
123
|
-
|
|
124
|
-
## 0.3.1-pre.1 (unreleased)
|
|
125
|
-
|
|
126
|
-
1. Removed `dev.ts` file.
|
|
127
|
-
|
|
128
|
-
## 0.3.0
|
|
129
|
-
|
|
130
|
-
1. Removed AI Assistant Context files to be generated by the user with the provided prompts in the README.
|
|
131
|
-
|
|
132
|
-
## 0.2.8 (unreleased)
|
|
133
|
-
|
|
134
|
-
1. CLI now copies root `README.md` into the generated project as `README-template.md`.
|
|
135
|
-
2. Added `README-template.md` to `template/gitignore`.
|
|
136
|
-
3. Added `# AI Assistant Context` section to root `README.md` and `template/README.md` with prompts for generating AI coding assistant context files.
|
|
137
|
-
4. Revised Change Management step 6 in root `README.md` and `template/README.md`.
|
|
138
|
-
5. `.gitignore`'ing `bun.lock`.
|
|
139
|
-
|
|
140
|
-
## 0.2.8-pre.2
|
|
141
|
-
|
|
142
|
-
1. Removed `sideEffects` property from `package.json` as it is not a standard field.
|
|
143
|
-
2. Added references to npmjs and typescriptlang documentation for `package.json` and `tsconfig.json` in the README.
|
|
144
|
-
|
|
145
|
-
## 0.2.7
|
|
146
|
-
|
|
147
|
-
1. Changed `filter` property in `cdnRewritePlugin` in `scripts/build-lib-bundle.ts` to take import identifiers into account that do not have file extensions.
|
|
148
|
-
2. Changed `buildinfo.txt` generation in `scripts/buildinfo.ts` to read the version from `package.json` instead of relying on the `npm_package_version` environment variable. Enables correct version capture in monorepo setups.
|
|
149
|
-
|
|
150
|
-
## 0.2.6
|
|
151
|
-
|
|
152
|
-
1. Minor ToC and typo fixes in both README.md files (root and template).
|
|
153
|
-
2. Revised the Publish section in both README.md files.
|
|
154
|
-
|
|
155
|
-
## 0.2.5
|
|
156
|
-
|
|
157
|
-
1. Minor README updates.
|
|
158
|
-
2. Fixed `buildinfo.txt` in published package.
|
|
159
|
-
3. Fixed `buildinfo.test.ts` regex to accept semver prerelease identifiers.
|
|
160
|
-
|
|
161
|
-
## 0.2.4
|
|
162
|
-
|
|
163
|
-
1. Documented template caching in the Quick Start section with commands to pin the version or clear the cache.
|
|
164
|
-
2. Minor README updates: Revised Asset Resolution sections in root and template; Added introductory paragraph to Documentation section;
|
|
165
|
-
3. Moved git-upstream to `https://git.chimps.quest/trs/create-ts-lib.git`.
|
|
166
|
-
|
|
167
|
-
## 0.2.3
|
|
168
|
-
|
|
169
|
-
1. Updated change management workflow in `README.md` and `template/README.md`: build step now happens after merge (not before PR), so `buildinfo.txt` captures the correct git hash and artifacts are up to date before publish.
|
|
170
|
-
2. Added Change Management section to root and template `CLAUDE.md`.
|
|
171
|
-
|
|
172
|
-
## 0.2.2
|
|
173
|
-
|
|
174
|
-
1. Fixed `CHANGELOG.md` and `buildinfo.txt` copy paths in `cli.ts`: they were resolved relative to `template/` instead of the package root, causing the copy to fail. Refactored URL/path construction to derive all paths from a single `packageUrl`, eliminating redundant `fileURLToPath` calls at each copy site.
|
|
175
|
-
2. Added `buildinfo-template.txt` and `CHANGELOG-template.md` to `template/gitignore` so generated libraries do not track template files.
|
|
176
|
-
3. Added `example/` to the root `.gitignore` to exclude local test scaffold output.
|
|
177
|
-
4. Added a `bun run dist/cli.bundle.js -- example` snippet to the DevOps section of the README for quick local testing.
|
|
178
|
-
|
|
179
|
-
## 0.2.1
|
|
180
|
-
|
|
181
|
-
1. Added asset resolution documentation to root README: scoped asset folder convention, inline `import.meta.url` resolution, `fetch()` for isomorphic I/O, setup steps, checklist, and consumer README statement.
|
|
182
|
-
2. Updated template README with a reference to the asset resolution docs in the create-ts-lib README.
|
|
183
|
-
3. Updated both `CLAUDE.md` files.
|
|
184
|
-
4. Updated both `dev.ts` files to use inline `new URL('../', import.meta.url)`.
|
|
185
|
-
5. Removed `src/urls.ts` from root and template (not needed - inline resolution is sufficient).
|
|
186
|
-
|
|
187
|
-
## 0.1.0
|
|
188
|
-
|
|
189
|
-
1. First version of the template.
|
|
5
|
+
1. Package created.
|
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
|
-
|
|
412
|
+
npm update
|
|
413
|
+
npm install
|
|
434
414
|
|
|
435
415
|
bun run clean
|
|
436
416
|
bun run build
|
|
437
417
|
bun run tests
|
|
438
418
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
# see publish section for publish instructions
|
|
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.7+d5c1924
|
|
@@ -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.7",
|
|
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 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,32 @@ 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
|
-
# <
|
|
76
|
-
|
|
50
|
+
# <REGISTRY_AUTH_TOKEN_ENV_VAR: <REGISTRY_AUTH_TOKEN_ENV_VAR>
|
|
51
|
+
# <REGISTRY_ORIGIN_AND_PATH: <REGISTRY_ORIGIN_AND_PATH>
|
|
52
|
+
# e.g.
|
|
53
|
+
# registry.npmjs.org/
|
|
54
|
+
# forgejo.example.com/api/packages/<SCOPE_WITHOUT_AT>/npm/
|
|
77
55
|
```
|
|
78
56
|
|
|
79
|
-
|
|
57
|
+
Authenticate with the registry:
|
|
80
58
|
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
59
|
+
```bash
|
|
60
|
+
# registry.npmjs.org/
|
|
61
|
+
npm login
|
|
62
|
+
# or custom registry
|
|
63
|
+
export <REGISTRY_AUTH_TOKEN_ENV_VAR>=<AUTH_TOKEN>
|
|
64
|
+
# or
|
|
65
|
+
$env:<REGISTRY_AUTH_TOKEN_ENV_VAR> = "<AUTH_TOKEN>"
|
|
85
66
|
|
|
86
|
-
|
|
87
|
-
# authenticate
|
|
88
|
-
$env:BUN_PUBLISH_AUTH_TOKEN = "<BUN_PUBLISH_AUTH_TOKEN>"
|
|
89
|
-
# publish
|
|
90
|
-
bun publish
|
|
67
|
+
npm publish --registry https://<REGISTRY_ORIGIN_AND_PATH>
|
|
91
68
|
```
|
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
|
+
});
|