@temir.ra/create-test115 0.0.15 → 0.0.17

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/LICENSE +21 -0
  3. package/README.md +85 -36
  4. package/buildinfo.txt +1 -0
  5. package/dist/index.bundle.js +2 -2
  6. package/dist/index.bundle.js.map +5 -4
  7. package/dist/index.js +19 -15
  8. package/dist/urls.d.ts +4 -0
  9. package/dist/urls.d.ts.map +1 -0
  10. package/dist/urls.js +3 -0
  11. package/package.json +15 -7
  12. package/template/bun.lock +23 -0
  13. package/template/package.json +41 -31
  14. package/{dist/template/scripts/build-cdn.ts → template/scripts/build-lib-bundle.ts} +15 -17
  15. package/template/scripts/buildinfo.ts +4 -8
  16. package/template/src/urls.ts +2 -0
  17. package/template/tests/buildinfo.test.ts +13 -5
  18. package/template/tsconfig.build.json +1 -0
  19. package/template/tsconfig.json +4 -1
  20. package/dist/buildinfo.d.ts +0 -2
  21. package/dist/buildinfo.d.ts.map +0 -1
  22. package/dist/buildinfo.js +0 -2
  23. package/dist/template/CHANGELOG.md +0 -5
  24. package/dist/template/README.md +0 -29
  25. package/dist/template/package.json +0 -32
  26. package/dist/template/scripts/buildinfo.ts +0 -25
  27. package/dist/template/src/buildinfo.ts +0 -2
  28. package/dist/template/src/dev.ts +0 -5
  29. package/dist/template/src/index.ts +0 -0
  30. package/dist/template/tests/buildinfo.test.ts +0 -20
  31. package/dist/template/tsconfig.build.json +0 -18
  32. package/dist/template/tsconfig.json +0 -35
  33. package/template/scripts/build-cdn-map.json +0 -1
  34. package/template/scripts/build-cdn.ts +0 -158
  35. package/template/src/buildinfo.ts +0 -2
  36. /package/{dist/template/scripts/build-cdn-map.json → template/scripts/cdn-rewrite-map.json} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,50 @@
1
+ # Version 0
2
+
3
+ ## next
4
+
5
+ 1. Restructured the package files to comply with the "create-" template convention.
6
+
7
+ ## 0.3.0
8
+
9
+ 1. Updated `scripts/buildinfo.ts` to use `join` from `path` module for better cross-platform compatibility.
10
+ 2. Added `scripts/build-cdn.ts` to generate a bundled version of the library for CDN usage.
11
+ 3. Added `scripts/build-cdn-map.json` to configure import path rewrites for the CDN build.
12
+ 4. Cleaned up legacy fields `main`, `module`, and `types` from `package.json` to rely solely on the `exports` field for module resolution.
13
+ 5. Added `browser` condition to the `exports` field in `package.json` to specify the bundled version for CDN usage.
14
+ 6. Added `src/dev.ts` as a development entry point for testing and experimentation during development.
15
+ 7. Added QoL `clean` and `test` scripts to `package.json`.
16
+ 8. Updated `build` workflow in `package.json`. Now it runs `build:lib` to create JavaScript and declaration files, then runs `build:cdn` to create the bundled version for CDN, and finally runs `build:assets` as a placeholder for any future asset build steps.
17
+ 9. Added `description` metadata field to `package.json`.
18
+ 10. Updated `tsconfig.json` and `tsconfig.build.json` with opiniated settings for better development, build, and publishing experience.
19
+ 11. Added documentation for custom scripts and rationale for the selected values in `tsconfig.json`, `tsconfig.build.json`, and `package.json`.
20
+ 12. Updated Quick Start instructions to reflect the new scripts and workflow.
21
+ 13. Renamed `README.md` and `CHANGELOG.md` to `README.md.template` and `CHANGELOG.md.template` respectively, and added a `bun-create` configuration in `package.json` to rename them back during project creation.
22
+ 14. Added `gitignore` (note the missing dot) to the template to ensure that generated projects have a proper `.gitignore` file.
23
+
24
+ ## 0.2.0
25
+
26
+ 1. Added `tests/` directory for unit tests using Bun's built-in test runner.
27
+ 2. Updated `tsconfig.json` to include `tests/` in the `include` array to allow TypeScript to recognize test files during development, while still excluding them from the build output using `tsconfig.build.json`.
28
+ 3. Updated `tsconfig.build.json` to exclude `tests/` to ensure that test files are not included in the build output.
29
+ 4. Updated `tsconfig.json` to include `baseUrl` and `paths` for better module resolution and cleaner import statements in the source code.
30
+
31
+ ## 0.1.4
32
+
33
+ 1. Introduced `tsconfig.build.json` to separate build-specific TypeScript configuration from development configuration, allowing for more tailored settings for each use case.
34
+ 2. Updated scripts in `package.json` to utilize `tsconfig.build.json` for the build process, ensuring that the build is optimized and does not include unnecessary files or settings meant for development.
35
+
36
+ ## 0.1.3
37
+
38
+ 1. Added `--no-git` to `bun create` command in Quick Start instructions to allow users to choose when to initialize git repository.
39
+
40
+ ## 0.1.2
41
+
42
+ 1. Added `--no-install` to `bun create` command in Quick Start instructions to allow users to choose when to install dependencies.
43
+
44
+ ## 0.1.1
45
+
46
+ 1. Fixed github user in Quick Start instructions.
47
+
48
+ ## 0.1.0
49
+
50
+ 1. First version of the template.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Temir Ra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -9,11 +9,13 @@ This package serves as a template for creating Bun libraries. It includes a basi
9
9
  1. [`tsconfig.json` and `tsconfig.build.json`](#tsconfigjson-and-tsconfigbuildjson)
10
10
  2. [`package.json`](#packagejson)
11
11
  3. [Script `scripts/buildinfo.ts`](#script-scriptsbuildinfots)
12
- 4. [Script `scripts/build-cdn.ts`](#script-scriptsbuild-cdn-ts)
13
- 5. [CDN Map `scripts/build-cdn-map.json`](#cdn-map-scriptsbuild-cdn-mapjson)
12
+ 4. [Script `scripts/build-lib-bundle.ts`](#script-scriptsbuild-lib-bundlets)
13
+ 5. [CDN Map `scripts/cdn-rewrite-map.json`](#cdn-map-scriptscdn-rewrite-mapjson)
14
14
  3. [DevOps](#devops)
15
15
  1. [Change Management](#change-management)
16
16
  2. [Publish](#publish)
17
+ 1. [npmjs.org](#npmjsorg)
18
+ 2. [Custom registry](#custom-registry)
17
19
 
18
20
  # Quick Start
19
21
 
@@ -21,22 +23,21 @@ This package serves as a template for creating Bun libraries. It includes a basi
21
23
  # placeholder:
22
24
  # <PACKAGE: <PACKAGE>
23
25
 
24
- bun create temir-ra/bun-lib-template --no-install --no-git <PACKAGE>
26
+ bun create @temir.ra/ts-lib --no-install --no-git <PACKAGE>
25
27
  cd <PACKAGE>
26
- bun install
27
28
 
28
- bun run dev
29
- bun run test
29
+ bun install
30
30
 
31
31
  bun run build
32
32
 
33
+ bun run test
34
+ bun run dev
35
+
33
36
  bun publish
34
37
  ```
35
38
 
36
39
  # Documentation
37
40
 
38
- `README-template.md` and `CHANGELOG-template.md` are the actual documentation files for this template package. Whereas `README.md` and `CHANGELOG.md` are copied as part of the package creation process and should be modified by the user to reflect the specifics of their library.
39
-
40
41
  ## `tsconfig.json` and `tsconfig.build.json`
41
42
 
42
43
  ```json
@@ -45,17 +46,17 @@ bun publish
45
46
  "compilerOptions": {
46
47
 
47
48
  // supported JavaScript features and syntax in the emitted JavaScript files
48
- // ES2022 is a reasonable modern baseline
49
+ // "ES2022" is a reasonable modern baseline
49
50
  "target": "ES2022",
50
51
 
51
52
  // how import and export statements are written in the emitted JavaScript files
52
- // ESNext emits standard ES module syntax unchanged
53
+ // "ESNext" emits standard ES module syntax unchanged
53
54
  "module": "ESNext",
54
55
 
55
56
  // available built-in types
56
57
  "lib": [
57
58
  "ES2022", // standard JavaScript runtime APIs
58
- "DOM" // browser globals or import.meta.url
59
+ "DOM" // browser globals or `import.meta.url`
59
60
  ],
60
61
 
61
62
  // permissive about file extensions in import statements
@@ -68,6 +69,11 @@ bun publish
68
69
  // compatibility shims that make it easier to import CommonJS modules as if they were ES modules
69
70
  "esModuleInterop": true,
70
71
 
72
+ // enables TypeScript project references
73
+ // required for `tsc --build` to work correctly across monorepo packages
74
+ // creates `*.tsbuildinfo` files that speed up subsequent builds by only rebuilding packages that have changed since the last build
75
+ "composite": true,
76
+
71
77
  // do not type-check `.d.ts` files in `node_modules/`
72
78
  "skipLibCheck": true,
73
79
 
@@ -87,10 +93,14 @@ bun publish
87
93
  // during build, use `tsconfig.build.json` to override this setting and emit JavaScript files for distribution
88
94
  "emitDeclarationOnly": true,
89
95
 
90
- // the directory where the emitted JavaScript and declaration files will be placed when building the library for distribution
91
- // matches the `files` field in `package.json` that determines what gets published
96
+ // the directory where the emitted JavaScript and declaration files will be placed when building the library
92
97
  "outDir": "./dist",
93
98
 
99
+ // sets source root directory to mirror in the "outDir" when emitting files
100
+ // during development, it is set to the project root so that all files in the project are included in the editor features and type-checking
101
+ // during build, `tsconfig.build.json` narrows it down to only `src/`
102
+ "rootDir": ".",
103
+
94
104
  // the base directory to resolve non-relative module imports
95
105
  "baseUrl": ".",
96
106
 
@@ -109,7 +119,8 @@ bun publish
109
119
  "include": [
110
120
  "src/**/*.ts",
111
121
  "tests/**/*.ts",
112
- "scripts/**/*.ts"
122
+ "scripts/**/*.ts",
123
+ "scripts/**/*.json"
113
124
  ],
114
125
  "exclude": [
115
126
  "node_modules",
@@ -119,9 +130,9 @@ bun publish
119
130
  }
120
131
  ```
121
132
 
122
- During development, the `tsconfig.json` configuration prevents emitting JavaScript files and relies on the executing environment to handle TypeScript directly. The `include` and `exclude` settings ensure that all relevant TypeScript files are included in the development environment.
133
+ During development, the `tsconfig.json` configuration prevents emitting JavaScript files and relies on the executing environment to handle TypeScript directly. The settings include `src/`, `tests/`, and `scripts/` for type-checking and editor features.
123
134
 
124
- When building the library for distribution, the `tsconfig.build.json` configuration overrides the settings to emit JavaScript files and include only the `src/` files.
135
+ When building the library for distribution, the `tsconfig.build.json` configuration overrides the settings to emit JavaScript files while including only the `src/`.
125
136
 
126
137
  ```json
127
138
  {
@@ -130,7 +141,10 @@ When building the library for distribution, the `tsconfig.build.json` configurat
130
141
 
131
142
  "compilerOptions": {
132
143
 
133
- // `nodenext` is the strictest and most forward-compatible ESM mode
144
+ // sets root directory to mirror in the "outDir" when emitting files
145
+ "rootDir": "./src",
146
+
147
+ // "nodenext" is the strictest and most forward-compatible ESM mode
134
148
  // imports must include explicit `.js` file extensions
135
149
  "module": "nodenext",
136
150
  "moduleResolution": "nodenext",
@@ -159,9 +173,19 @@ When building the library for distribution, the `tsconfig.build.json` configurat
159
173
 
160
174
  ```json
161
175
  {
162
- "name": "package",
176
+ "name": "",
163
177
  "version": "0.0.0",
178
+
164
179
  "description": "",
180
+ "author": "",
181
+ "license": "",
182
+
183
+ "keywords": ["typescript"],
184
+
185
+ "repository": {
186
+ "type": "git",
187
+ "url": ""
188
+ },
165
189
 
166
190
  // "module" makes every `.js` file in the package to be treated as an ES module unless explicitly named `.cjs`
167
191
  "type": "module",
@@ -180,9 +204,14 @@ When building the library for distribution, the `tsconfig.build.json` configurat
180
204
  }
181
205
  },
182
206
 
207
+ // specifies the entry point for the CLI executable exposed when the package is installed globally or as a dependency
208
+ "bin": "./dist/cli.js",
209
+
183
210
  // files to include in the published package
184
211
  "files": [
185
- "dist"
212
+ "dist",
213
+ "CHANGELOG.md",
214
+ "buildinfo.txt"
186
215
  ],
187
216
 
188
217
  "scripts": {
@@ -197,16 +226,15 @@ When building the library for distribution, the `tsconfig.build.json` configurat
197
226
  "test": "bun test",
198
227
 
199
228
  // runs all build steps in sequence
200
- "build": "bun run build:lib && bun run build:cdn && bun run build:assets",
229
+ "build": "bun run build:lib && bun run build:lib-bundle",
201
230
 
202
231
  // uses `tsconfig.build.json` to compile the TypeScript source files
203
232
  "build:lib": "tsc --project tsconfig.build.json",
233
+ // bundles the library for distribution in both ESM and IIFE formats
234
+ "build:lib-bundle": "bun run scripts/build-lib-bundle.ts",
204
235
 
205
- // bundles the library for CDN distribution in both ESM and IIFE formats
206
- "build:cdn": "bun run scripts/build-cdn.ts",
207
-
208
- // placeholder for any asset build steps (e.g. copying static files, generating documentation, etc.)
209
- "build:assets": "echo 'no assets to build'",
236
+ // builds the CLI (set by "bin" field) for distribution
237
+ "build:cli-bundle": "bun build src/cli.ts --outdir dist --target node --format esm --minify --sourcemap=external",
210
238
 
211
239
  // type checks the TypeScript source files without emitting any output
212
240
  "typecheck": "tsc --noEmit",
@@ -224,30 +252,51 @@ When building the library for distribution, the `tsconfig.build.json` configurat
224
252
 
225
253
  ## Script `scripts/buildinfo.ts`
226
254
 
227
- This script overwrites `src/buildinfo.ts` with the current version from `package.json` and the current git hash (if available).
255
+ This script overwrites `buildinfo.txt` with the current version from `package.json` and the current git hash (if available). The generated `buildinfo.txt` file is included in the published package and can be used for debugging and support purposes to quickly identify the exact version of the library being used, along with the corresponding source code in the repository.
228
256
 
229
- ## Script `scripts/build-cdn.ts`
257
+ ## Script `scripts/build-lib-bundle.ts`
230
258
 
231
- This script bundles the library for CDN distribution in both ESM and IIFE formats. It reads the `exports` field from `package.json` to determine the entry points for the library and generates bundled files in the `dist/` directory. A custom condition `entrypoint` is used in the `exports` field to specify the entry point for the CDN build.
259
+ This script bundles the library for distribution in both ESM and IIFE formats. It reads the `exports` field from `package.json` to determine the entry points for the library and generates bundled files. A custom condition `entrypoint` is used in the `exports` field to specify the entry point for the build.
232
260
 
233
- During the bundling process, the import paths in the source files can be rewritten to point to a CDN URL of a package, instead of using the package name that would be resolved from `node_modules/`.
261
+ During the bundling process, the import specifiers in the source files can be rewritten to point to a CDN URL of a package, instead of using the package name that would be resolved from `node_modules/`.
234
262
 
235
- The list of import paths to rewrite and their corresponding CDN URLs can be configured in the `scripts/build-cdn-map.json` file.
263
+ The list of import specifiers to rewrite and their corresponding CDN URLs can be configured in the `scripts/cdn-rewrite-map.json` file.
236
264
 
237
- ## CDN Map `scripts/build-cdn-map.json`
265
+ ## CDN Map `scripts/cdn-rewrite-map.json`
238
266
 
239
- This JSON file contains a mapping of module import paths to their corresponding CDN URLs. During the CDN build process, if an import path in the source files matches a key in this map, it will be replaced with the corresponding CDN URL in the bundled output.
267
+ This JSON file contains a mapping of module import specifiers to their corresponding CDN URLs. During the CDN build process, if an import specifier in the source files matches a key in this map, it will be replaced with the corresponding CDN URL in the bundled output.
240
268
 
241
- The URL can contain the placeholder `<VERSION>` which will be replaced with the current version of that package from `package.json`.
269
+ The URL can contain the placeholder `<VERSION>` which will be replaced with the current version of a package from `package.json` that matches the import specifier.
242
270
 
243
271
  ```json
244
272
  {
245
- "package-name": "https://cdn.jsdelivr.net/npm/package-name@<VERSION>/dist/index.bundle.js"
273
+ "import-specifier": "https://cdn.jsdelivr.net/npm/package-name@<VERSION>/dist/index.bundle.js"
246
274
  }
247
275
  ```
248
276
 
249
277
  - Keys are the import specifiers as they appear in source code.
250
- - Values are CDN URLs. The URL can contain the placeholder `<VERSION>` which will be replaced with the current version of that package from `package.json`.
278
+ - Values are CDN URLs. The URL can contain the placeholder `<VERSION>` which will be replaced with the current version of a package from `package.json` that matches the import specifier.
279
+
280
+ ## `"bin"` field in `package.json`
281
+
282
+ The `"bin"` field in `package.json` specifies the entry point for the CLI executable exposed when the package is installed globally or as a dependency.
283
+
284
+ If the package is intended to be used as a CLI tool, the `"bin"` field should point to the JavaScript file that serves as the entry point for the CLI. This file will be bundled during the build process (e.g. using `build:cli-bundle` script) and included in the published package.
285
+
286
+ ```json
287
+ {
288
+ "exports": ...,
289
+ "bin": "./dist/cli.js",
290
+ "files": ...,
291
+ "scripts": {
292
+ ...,
293
+ "build": "... && bun run build:cli-bundle",
294
+ ...,
295
+ "build:cli-bundle": "bun build src/cli.ts --outdir dist --target node --format esm --minify --sourcemap=external",
296
+ ...,
297
+ }
298
+ }
299
+ ```
251
300
 
252
301
  # DevOps
253
302
 
@@ -268,7 +317,7 @@ The URL can contain the placeholder `<VERSION>` which will be replaced with the
268
317
  bun publish --registry https://registry.npmjs.org/ --access public
269
318
  ```
270
319
 
271
- ### Custom registry with `bun`
320
+ ### Custom registry
272
321
 
273
322
  ```bash
274
323
  # placeholder:
package/buildinfo.txt ADDED
@@ -0,0 +1 @@
1
+ 0.0.16+ac7caf3
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{cpSync as C,readFileSync as E,writeFileSync as G}from"fs";import{resolve as q,basename as H}from"path";import{fileURLToPath as I}from"url";var x=process.argv[2];if(!x)console.error("Usage: bun create my-template <destination>"),process.exit(1);var z=q(process.cwd(),x),A=H(z),J=q(I(import.meta.url),"../../template");C(J,z,{recursive:!0});var B=q(z,"package.json"),K=E(B,"utf8");G(B,K.replaceAll("{{PACKAGE_NAME}}",A));console.log(`✔ Created ${A}`);console.log(` cd ${x} && bun install`);
2
+ import{cpSync as p,readFileSync as l,writeFileSync as m}from"fs";import{resolve as o,basename as f}from"path";import{fileURLToPath as u}from"url";var a=new URL(".",import.meta.url),d=new URL("../buildinfo.txt",a),i=new URL("../template",a);try{let e=process.argv[2];if(!e)throw Error("Destination path is required. Usage: `bun/npm create <template> <destination>`");let t=o(process.cwd(),e),n=f(t),c=o(u(i));p(c,t,{recursive:!0});let s=o(t,"package.json"),r=JSON.parse(l(s,"utf-8"));r.name=n,r.version="0.0.0",m(s,JSON.stringify(r,null,2)),console.log(`Template has been successfully instantiated at '${t}' with package name '${n}'.`)}catch(e){let t=e instanceof Error?e:Error(String(e));console.error("Error:",t.message),process.exit(1)}
3
3
 
4
- //# debugId=B480A6DF82A2DA2A64756E2164756E21
4
+ //# debugId=8906CC2F738BD0F464756E2164756E21
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["..\\src\\index.ts"],
3
+ "sources": ["..\\src\\index.ts", "..\\src\\urls.ts"],
4
4
  "sourcesContent": [
5
- "#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, writeFileSync } from 'fs';\r\nimport { resolve, basename } from 'path';\r\nimport { fileURLToPath } from 'url';\r\n\r\n\r\nconst dest = process.argv[2];\r\nif (!dest) {\r\n console.error('Usage: bun create my-template <destination>');\r\n process.exit(1);\r\n}\r\n\r\nconst destDir = resolve(process.cwd(), dest);\r\nconst packageName = basename(destDir);\r\n\r\n// template/ dir is relative to the installed package\r\nconst templateDir = resolve(fileURLToPath(import.meta.url), '../../template');\r\n\r\n// Copy template to destination\r\ncpSync(templateDir, destDir, { recursive: true });\r\n\r\n// Replace placeholders in package.json\r\nconst pkgPath = resolve(destDir, 'package.json');\r\nconst pkg = readFileSync(pkgPath, 'utf8');\r\nwriteFileSync(pkgPath, pkg.replaceAll('{{PACKAGE_NAME}}', packageName));\r\n\r\nconsole.log(`✔ Created ${packageName}`);\r\nconsole.log(` cd ${dest} && bun install`);\r\n"
5
+ "#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, writeFileSync } from 'fs';\r\nimport { resolve, basename } from 'path';\r\nimport { fileURLToPath } from 'url';\r\nimport { templateUrl } from './urls.js';\r\n\r\n\r\ntry {\r\n\r\n const dest = process.argv[2];\r\n if (!dest) throw new Error('Destination path is required. Usage: `bun/npm create <template> <destination>`');\r\n\r\n const destDir = resolve(process.cwd(), dest);\r\n const packageName = basename(destDir);\r\n\r\n const templateDir = resolve(fileURLToPath(templateUrl));\r\n\r\n cpSync(templateDir, destDir, { recursive: true });\r\n\r\n const packageManifestPath = resolve(destDir, 'package.json');\r\n const packageManifest = JSON.parse(readFileSync(packageManifestPath, 'utf-8'));\r\n\r\n packageManifest.name = packageName;\r\n packageManifest.version = '0.0.0';\r\n\r\n writeFileSync(packageManifestPath, JSON.stringify(packageManifest, null, 2));\r\n\r\n console.log(`Template has been successfully instantiated at '${destDir}' 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",
6
+ "export const distUrl = new URL('.', import.meta.url);\r\nexport const buildinfoUrl = new URL('../buildinfo.txt', distUrl);\r\nexport const templateUrl = new URL('../template', distUrl);\r\n"
6
7
  ],
7
- "mappings": ";AAEA,iBAAS,kBAAQ,mBAAc,WAC/B,kBAAS,cAAS,aAClB,wBAAS,YAGT,IAAM,EAAO,QAAQ,KAAK,GAC1B,GAAI,CAAC,EACD,QAAQ,MAAM,6CAA6C,EAC3D,QAAQ,KAAK,CAAC,EAGlB,IAAM,EAAU,EAAQ,QAAQ,IAAI,EAAG,CAAI,EACrC,EAAc,EAAS,CAAO,EAG9B,EAAc,EAAQ,EAAc,YAAY,GAAG,EAAG,gBAAgB,EAG5E,EAAO,EAAa,EAAS,CAAE,UAAW,EAAK,CAAC,EAGhD,IAAM,EAAU,EAAQ,EAAS,cAAc,EACzC,EAAM,EAAa,EAAS,MAAM,EACxC,EAAc,EAAS,EAAI,WAAW,mBAAoB,CAAW,CAAC,EAEtE,QAAQ,IAAI,aAAY,GAAa,EACrC,QAAQ,IAAI,QAAQ,kBAAqB",
8
- "debugId": "B480A6DF82A2DA2A64756E2164756E21",
8
+ "mappings": ";AAEA,iBAAS,kBAAQ,mBAAc,WAC/B,kBAAS,cAAS,aAClB,wBAAS,YCJF,IAAM,EAAU,IAAI,IAAI,IAAK,YAAY,GAAG,EACtC,EAAe,IAAI,IAAI,mBAAoB,CAAO,EAClD,EAAc,IAAI,IAAI,cAAe,CAAO,EDMzD,GAAI,CAEA,IAAM,EAAO,QAAQ,KAAK,GAC1B,GAAI,CAAC,EAAM,MAAU,MAAM,gFAAgF,EAE3G,IAAM,EAAU,EAAQ,QAAQ,IAAI,EAAG,CAAI,EACrC,EAAc,EAAS,CAAO,EAE9B,EAAc,EAAQ,EAAc,CAAW,CAAC,EAEtD,EAAO,EAAa,EAAS,CAAE,UAAW,EAAK,CAAC,EAEhD,IAAM,EAAsB,EAAQ,EAAS,cAAc,EACrD,EAAkB,KAAK,MAAM,EAAa,EAAqB,OAAO,CAAC,EAE7E,EAAgB,KAAO,EACvB,EAAgB,QAAU,QAE1B,EAAc,EAAqB,KAAK,UAAU,EAAiB,KAAM,CAAC,CAAC,EAE3E,QAAQ,IAAI,mDAAmD,yBAA+B,KAAe,EAGjH,MAAO,EAAO,CACV,IAAM,EAAM,aAAiB,MAAQ,EAAY,MAAM,OAAO,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAU,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC",
9
+ "debugId": "8906CC2F738BD0F464756E2164756E21",
9
10
  "names": []
10
11
  }
package/dist/index.js CHANGED
@@ -2,20 +2,24 @@
2
2
  import { cpSync, readFileSync, writeFileSync } from 'fs';
3
3
  import { resolve, basename } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- const dest = process.argv[2];
6
- if (!dest) {
7
- console.error('Usage: bun create my-template <destination>');
5
+ import { templateUrl } from './urls.js';
6
+ try {
7
+ const dest = process.argv[2];
8
+ if (!dest)
9
+ throw new Error('Destination path is required. Usage: `bun/npm create <template> <destination>`');
10
+ const destDir = resolve(process.cwd(), dest);
11
+ const packageName = basename(destDir);
12
+ const templateDir = resolve(fileURLToPath(templateUrl));
13
+ cpSync(templateDir, destDir, { recursive: true });
14
+ const packageManifestPath = resolve(destDir, 'package.json');
15
+ const packageManifest = JSON.parse(readFileSync(packageManifestPath, 'utf-8'));
16
+ packageManifest.name = packageName;
17
+ packageManifest.version = '0.0.0';
18
+ writeFileSync(packageManifestPath, JSON.stringify(packageManifest, null, 2));
19
+ console.log(`Template has been successfully instantiated at '${destDir}' with package name '${packageName}'.`);
20
+ }
21
+ catch (error) {
22
+ const err = error instanceof Error ? error : new Error(String(error));
23
+ console.error('Error:', err.message);
8
24
  process.exit(1);
9
25
  }
10
- const destDir = resolve(process.cwd(), dest);
11
- const packageName = basename(destDir);
12
- // template/ dir is relative to the installed package
13
- const templateDir = resolve(fileURLToPath(import.meta.url), '../../template');
14
- // Copy template to destination
15
- cpSync(templateDir, destDir, { recursive: true });
16
- // Replace placeholders in package.json
17
- const pkgPath = resolve(destDir, 'package.json');
18
- const pkg = readFileSync(pkgPath, 'utf8');
19
- writeFileSync(pkgPath, pkg.replaceAll('{{PACKAGE_NAME}}', packageName));
20
- console.log(`✔ Created ${packageName}`);
21
- console.log(` cd ${dest} && bun install`);
package/dist/urls.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const distUrl: URL;
2
+ export declare const buildinfoUrl: URL;
3
+ export declare const templateUrl: URL;
4
+ //# sourceMappingURL=urls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../src/urls.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,KAAgC,CAAC;AACrD,eAAO,MAAM,YAAY,KAAuC,CAAC;AACjE,eAAO,MAAM,WAAW,KAAkC,CAAC"}
package/dist/urls.js ADDED
@@ -0,0 +1,3 @@
1
+ export const distUrl = new URL('.', import.meta.url);
2
+ export const buildinfoUrl = new URL('../buildinfo.txt', distUrl);
3
+ export const templateUrl = new URL('../template', distUrl);
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@temir.ra/create-test115",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "",
5
+ "author": "",
6
+ "license": "",
7
+ "keywords": [
8
+ "typescript"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": ""
13
+ },
5
14
  "type": "module",
6
15
  "exports": {
7
16
  ".": {
@@ -11,21 +20,20 @@
11
20
  "types": "./dist/index.d.ts"
12
21
  }
13
22
  },
14
- "bin": {
15
- "create-test115": "./dist/index.bundle.js"
16
- },
23
+ "bin": "./dist/index.bundle.js",
17
24
  "files": [
18
25
  "dist",
26
+ "CHANGELOG.md",
27
+ "buildinfo.txt",
19
28
  "template"
20
29
  ],
21
30
  "scripts": {
22
31
  "clean": "rm -rf dist/",
23
32
  "prebuild": "bun run scripts/buildinfo.ts",
24
33
  "test": "bun test",
25
- "build": "bun run build:lib && bun run build:cdn && bun run build:assets",
34
+ "build": "bun run build:lib && bun run build:lib-bundle",
26
35
  "build:lib": "tsc --project tsconfig.build.json",
27
- "build:cdn": "bun run scripts/build-cdn.ts",
28
- "build:assets": "cp -R template/ dist/template/",
36
+ "build:lib-bundle": "bun run scripts/build-lib-bundle.ts",
29
37
  "typecheck": "tsc --noEmit",
30
38
  "dev": "bun run --watch src/dev.ts"
31
39
  },
@@ -0,0 +1,23 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "configVersion": 1,
4
+ "workspaces": {
5
+ "": {
6
+ "devDependencies": {
7
+ "@types/bun": "latest",
8
+ "typescript": "^5.9.3",
9
+ },
10
+ },
11
+ },
12
+ "packages": {
13
+ "@types/bun": ["@types/bun@1.3.9", "", { "dependencies": { "bun-types": "1.3.9" } }, "sha512-KQ571yULOdWJiMH+RIWIOZ7B2RXQGpL1YQrBtLIV3FqDcCu6FsbFUBwhdKUlCKUpS3PJDsHlJ1QKlpxoVR+xtw=="],
14
+
15
+ "@types/node": ["@types/node@25.3.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-4K3bqJpXpqfg2XKGK9bpDTc6xO/xoUP/RBWS7AtRMug6zZFaRekiLzjVtAoZMquxoAbzBvy5nxQ7veS5eYzf8A=="],
16
+
17
+ "bun-types": ["bun-types@1.3.9", "", { "dependencies": { "@types/node": "*" } }, "sha512-+UBWWOakIP4Tswh0Bt0QD0alpTY8cb5hvgiYeWCMet9YukHbzuruIEeXC2D7nMJPB12kbh8C7XJykSexEqGKJg=="],
18
+
19
+ "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
20
+
21
+ "undici-types": ["undici-types@7.18.2", "", {}, "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w=="],
22
+ }
23
+ }
@@ -1,32 +1,42 @@
1
- {
2
- "name": "",
3
- "version": "",
4
- "description": "",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "entrypoint": "./src/index.ts",
9
- "browser": "./dist/index.bundle.js",
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- }
13
- },
14
- "files": [
15
- "dist"
16
- ],
17
- "scripts": {
18
- "clean": "rm -rf dist/",
19
- "prebuild": "bun run scripts/buildinfo.ts",
20
- "test": "bun test",
21
- "build": "bun run build:lib && bun run build:cdn && bun run build:assets",
22
- "build:lib": "tsc --project tsconfig.build.json",
23
- "build:cdn": "bun run scripts/build-cdn.ts",
24
- "build:assets": "cp src/assets/* dist/assets/",
25
- "typecheck": "tsc --noEmit",
26
- "dev": "bun run --watch src/dev.ts"
27
- },
28
- "devDependencies": {
29
- "@types/bun": "latest",
30
- "typescript": "^5.9.3"
31
- }
1
+ {
2
+ "name": "",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "author": "",
6
+ "license": "",
7
+ "keywords": [
8
+ "typescript"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": ""
13
+ },
14
+ "type": "module",
15
+ "exports": {
16
+ ".": {
17
+ "entrypoint": "./src/index.ts",
18
+ "browser": "./dist/index.bundle.js",
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "CHANGELOG.md",
26
+ "buildinfo.txt"
27
+ ],
28
+ "scripts": {
29
+ "clean": "rm -rf dist/",
30
+ "prebuild": "bun run scripts/buildinfo.ts",
31
+ "test": "bun test",
32
+ "build": "bun run build:lib && bun run build:lib-bundle",
33
+ "build:lib": "tsc --project tsconfig.build.json",
34
+ "build:lib-bundle": "bun run scripts/build-lib-bundle.ts",
35
+ "typecheck": "tsc --noEmit",
36
+ "dev": "bun run --watch src/dev.ts"
37
+ },
38
+ "devDependencies": {
39
+ "@types/bun": "latest",
40
+ "typescript": "^5.9.3"
41
+ }
32
42
  }
@@ -1,12 +1,10 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { join } from 'path';
3
- import CDN_MAP from 'scripts/build-cdn-map.json';
3
+ import CDN_REWRITE_MAP from 'scripts/cdn-rewrite-map.json';
4
4
 
5
5
 
6
6
  interface ExportConditions {
7
-
8
7
  [key: string]: string | undefined;
9
-
10
8
  import?: string;
11
9
  types?: string;
12
10
  browser?: string;
@@ -36,9 +34,9 @@ function getManifest(packageIdentifier?: string): PackageManifest {
36
34
  manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
37
35
  } catch {
38
36
  if (packageIdentifier)
39
- throw new Error("[build-cdn] Could not read manifest for '" + packageIdentifier + "' at '" + manifestPath + "'. Is it installed?");
37
+ throw new Error("[scripts/build-lib-bundle.ts] Could not read manifest for '" + packageIdentifier + "' at '" + manifestPath + "'. Is it installed?");
40
38
  else
41
- throw new Error("[build-cdn] Could not read package manifest at '" + manifestPath + "'.");
39
+ throw new Error("[scripts/build-lib-bundle.ts] Could not read package manifest at '" + manifestPath + "'.");
42
40
  }
43
41
 
44
42
  return manifest;
@@ -48,11 +46,11 @@ function getManifest(packageIdentifier?: string): PackageManifest {
48
46
  function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
49
47
 
50
48
  const exports = packageManifest.exports;
51
- if (!exports) throw new Error('[build-cdn] No exports field found in package.json.');
49
+ if (!exports) throw new Error('[scripts/build-lib-bundle.ts] No exports field found in package.json.');
52
50
 
53
51
  const entrypoints = Object.entries(exports)
54
52
  .map(([key, conditions]) => {
55
- if (!conditions.entrypoint) throw new Error(`[build-cdn] Export '${key}' does not have an 'entrypoint' condition.`);
53
+ if (!conditions.entrypoint) throw new Error(`[scripts/build-lib-bundle.ts] Export '${key}' does not have an 'entrypoint' condition.`);
56
54
  return conditions.entrypoint;
57
55
  });
58
56
 
@@ -72,11 +70,11 @@ function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string
72
70
  };
73
71
 
74
72
  version = dependencies[packageIdentifier];
75
- if (!version) throw new Error(`[build-cdn] Package '${packageIdentifier}' is not listed in dependencies.`);
73
+ if (!version) throw new Error(`[scripts/build-lib-bundle.ts] Package '${packageIdentifier}' is not listed in dependencies.`);
76
74
 
77
75
  }
78
76
  else {
79
- if (!manifest.version) throw new Error('[build-cdn] Package manifest does not contain a version field.');
77
+ if (!manifest.version) throw new Error('[scripts/build-lib-bundle.ts] Package manifest does not contain a version field.');
80
78
  version = manifest.version;
81
79
  }
82
80
 
@@ -95,7 +93,7 @@ const cdnRewritePlugin = {
95
93
  setup(build: any) {
96
94
 
97
95
  const resolved = new Map<string, string>();
98
- for (const [importSpecifier, urlTemplate] of Object.entries(CDN_MAP) as [string, string][]) {
96
+ for (const [importSpecifier, urlTemplate] of Object.entries(CDN_REWRITE_MAP) as [string, string][]) {
99
97
  const url = resolveCdnUrl(importSpecifier, urlTemplate);
100
98
  resolved.set(importSpecifier, url);
101
99
  console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
@@ -111,11 +109,11 @@ const cdnRewritePlugin = {
111
109
 
112
110
 
113
111
  const entrypoints = getManifestEntrypoints(getManifest());
114
- console.log('[build-cdn] Entrypoints:', entrypoints);
112
+ console.log('[scripts/build-lib-bundle.ts] Entrypoints:', entrypoints);
115
113
 
116
114
  let buildResult;
117
115
 
118
- console.log('[build-cdn] Starting ESM CDN bundle build...');
116
+ console.log('[scripts/build-lib-bundle.ts] Starting ESM bundle build...');
119
117
  buildResult = await Bun.build({
120
118
  entrypoints,
121
119
  outdir: 'dist',
@@ -128,15 +126,15 @@ buildResult = await Bun.build({
128
126
  });
129
127
 
130
128
  if (!buildResult.success) {
131
- console.error('[build-cdn] Build failed:');
129
+ console.error('[scripts/build-lib-bundle.ts] Build failed:');
132
130
  for (const message of buildResult.logs) {
133
131
  console.error(message);
134
132
  }
135
133
  process.exit(1);
136
134
  }
137
- console.log('[build-cdn] ESM CDN bundle build completed successfully.');
135
+ console.log('[scripts/build-lib-bundle.ts] ESM bundle build completed successfully.');
138
136
 
139
- console.log('[build-cdn] Starting IIFE CDN bundle build...');
137
+ console.log('[scripts/build-lib-bundle.ts] Starting IIFE bundle build...');
140
138
  buildResult = await Bun.build({
141
139
  entrypoints,
142
140
  outdir: 'dist',
@@ -149,10 +147,10 @@ buildResult = await Bun.build({
149
147
  });
150
148
 
151
149
  if (!buildResult.success) {
152
- console.error('[build-cdn] Build failed:');
150
+ console.error('[scripts/build-lib-bundle.ts] Build failed:');
153
151
  for (const message of buildResult.logs) {
154
152
  console.error(message);
155
153
  }
156
154
  process.exit(1);
157
155
  }
158
- console.log('[build-cdn] IIFE CDN bundle build completed successfully.');
156
+ console.log('[scripts/build-lib-bundle.ts] IIFE bundle build completed successfully.');
@@ -1,9 +1,8 @@
1
1
  import { execSync } from 'child_process';
2
2
  import { writeFileSync } from 'fs';
3
- import { join } from 'path';
4
3
 
5
4
 
6
- const BUILD_INFO_FILE = join('src', 'buildinfo.ts');
5
+ const BUILD_INFO_FILE = 'buildinfo.txt';
7
6
  const GIT_COMMAND = 'git rev-parse --short HEAD';
8
7
 
9
8
  const version = process.env.npm_package_version ?? '0.0.0';
@@ -15,11 +14,8 @@ try {
15
14
  .trim();
16
15
  } catch { }
17
16
 
18
- const buildInfo = gitHash ? `${version}+${gitHash}` : version;
17
+ const buildinfo = gitHash ? `${version}+${gitHash}` : version;
19
18
 
20
- writeFileSync(
21
- BUILD_INFO_FILE,
22
- `// auto-generated by scripts/buildinfo.ts\nexport const buildInfo = '${buildInfo}';\n`
23
- );
19
+ writeFileSync(BUILD_INFO_FILE, buildinfo);
24
20
 
25
- console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildInfo}`);
21
+ console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildinfo}`);
@@ -0,0 +1,2 @@
1
+ export const distUrl = new URL('.', import.meta.url);
2
+ export const buildinfoUrl = new URL('../buildinfo.txt', distUrl);
@@ -1,20 +1,28 @@
1
1
  import { describe, it, expect } from 'bun:test';
2
- import { buildInfo } from '@/buildinfo';
2
+ import { readFileSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+ import { buildinfoUrl } from '@/urls';
3
5
 
4
6
 
5
7
  describe('buildInfo', () => {
6
8
 
7
9
  it('should follow semantic versioning format with optional commit hash', () => {
8
- expect(buildInfo).toMatch(/^\d+\.\d+\.\d+(\+[0-9a-f]+)?$/);
10
+ const buildinfoPath = fileURLToPath(buildinfoUrl);
11
+ const buildinfo = readFileSync(buildinfoPath, 'utf-8').trim();
12
+ expect(buildinfo).toMatch(/^\d+\.\d+\.\d+(\+[0-9a-f]+)?$/);
9
13
  });
10
14
 
11
15
  it('should not contain whitespace', () => {
12
- expect(buildInfo).not.toMatch(/\s/);
16
+ const buildinfoPath = fileURLToPath(buildinfoUrl);
17
+ const buildinfo = readFileSync(buildinfoPath, 'utf-8').trim();
18
+ expect(buildinfo).not.toMatch(/\s/);
13
19
  });
14
20
 
15
21
  it('should not be empty or dash', () => {
16
- expect(buildInfo.length).toBeGreaterThan(0);
17
- expect(buildInfo).not.toBe('-');
22
+ const buildinfoPath = fileURLToPath(buildinfoUrl);
23
+ const buildinfo = readFileSync(buildinfoPath, 'utf-8').trim();
24
+ expect(buildinfo.length).toBeGreaterThan(0);
25
+ expect(buildinfo).not.toBe('-');
18
26
  });
19
27
 
20
28
  });
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
+ "rootDir": "./src",
4
5
  "module": "nodenext",
5
6
  "moduleResolution": "nodenext",
6
7
  "emitDeclarationOnly": false,
@@ -9,6 +9,7 @@
9
9
  "moduleResolution": "bundler",
10
10
  "strict": true,
11
11
  "esModuleInterop": true,
12
+ "composite": true,
12
13
  "skipLibCheck": true,
13
14
  "forceConsistentCasingInFileNames": true,
14
15
  "resolveJsonModule": true,
@@ -16,6 +17,7 @@
16
17
  "declarationMap": true,
17
18
  "emitDeclarationOnly": true,
18
19
  "outDir": "./dist",
20
+ "rootDir": ".",
19
21
  "baseUrl": ".",
20
22
  "paths": {
21
23
  "@/*": [
@@ -26,7 +28,8 @@
26
28
  "include": [
27
29
  "src/**/*.ts",
28
30
  "tests/**/*.ts",
29
- "scripts/**/*.ts"
31
+ "scripts/**/*.ts",
32
+ "scripts/**/*.json"
30
33
  ],
31
34
  "exclude": [
32
35
  "node_modules",
@@ -1,2 +0,0 @@
1
- export declare const buildInfo = "0.0.14+ac7caf3";
2
- //# sourceMappingURL=buildinfo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildinfo.d.ts","sourceRoot":"","sources":["../src/buildinfo.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,mBAAmB,CAAC"}
package/dist/buildinfo.js DELETED
@@ -1,2 +0,0 @@
1
- // auto-generated by scripts/buildinfo.ts
2
- export const buildInfo = '0.0.14+ac7caf3';
@@ -1,5 +0,0 @@
1
- # Version 0
2
-
3
- ## 0.0.0
4
-
5
- 1. Versioning initialized.
@@ -1,29 +0,0 @@
1
- # Introduction
2
-
3
- *&lt;INTRO TEXT&gt;*
4
-
5
- ## Table of Contents
6
-
7
- 1. [Quick Start](#quick-start)
8
- 2. [Documentation](#documentation)
9
- 3. [DevOps](#devops)
10
- 1. [Change Management](#change-management)
11
- 2. [Publish](#publish)
12
-
13
- # Quick Start
14
-
15
- *&lt;QUICK START INSTRUCTIONS&gt;*
16
-
17
- # Documentation
18
-
19
- *&lt;DOCUMENTATION&gt;*
20
-
21
- # DevOps
22
-
23
- ## Change Management
24
-
25
- 1. Create a new branch for the change.
26
- 2. Make the changes and commit them to the branch.
27
- 3. Bump the version in [`package.json`](package.json).
28
- 4. Add an entry for the new version in [`CHANGELOG.md`](CHANGELOG.md).
29
- 5. Pull request the branch.
@@ -1,32 +0,0 @@
1
- {
2
- "name": "",
3
- "version": "",
4
- "description": "",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "entrypoint": "./src/index.ts",
9
- "browser": "./dist/index.bundle.js",
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- }
13
- },
14
- "files": [
15
- "dist"
16
- ],
17
- "scripts": {
18
- "clean": "rm -rf dist/",
19
- "prebuild": "bun run scripts/buildinfo.ts",
20
- "test": "bun test",
21
- "build": "bun run build:lib && bun run build:cdn && bun run build:assets",
22
- "build:lib": "tsc --project tsconfig.build.json",
23
- "build:cdn": "bun run scripts/build-cdn.ts",
24
- "build:assets": "cp src/assets/* dist/assets/",
25
- "typecheck": "tsc --noEmit",
26
- "dev": "bun run --watch src/dev.ts"
27
- },
28
- "devDependencies": {
29
- "@types/bun": "latest",
30
- "typescript": "^5.9.3"
31
- }
32
- }
@@ -1,25 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { writeFileSync } from 'fs';
3
- import { join } from 'path';
4
-
5
-
6
- const BUILD_INFO_FILE = join('src', 'buildinfo.ts');
7
- const GIT_COMMAND = 'git rev-parse --short HEAD';
8
-
9
- const version = process.env.npm_package_version ?? '0.0.0';
10
-
11
- let gitHash = '';
12
- try {
13
- gitHash = execSync(GIT_COMMAND, { stdio: ['ignore', 'pipe', 'ignore'] })
14
- .toString()
15
- .trim();
16
- } catch { }
17
-
18
- const buildInfo = gitHash ? `${version}+${gitHash}` : version;
19
-
20
- writeFileSync(
21
- BUILD_INFO_FILE,
22
- `// auto-generated by scripts/buildinfo.ts\nexport const buildInfo = '${buildInfo}';\n`
23
- );
24
-
25
- console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildInfo}`);
@@ -1,2 +0,0 @@
1
- // auto-generated by scripts/buildinfo.ts
2
- export const buildInfo = '-';
@@ -1,5 +0,0 @@
1
- const start = performance.now();
2
-
3
- // dev code
4
-
5
- console.log(`${(performance.now() - start).toFixed(3)}ms`);
File without changes
@@ -1,20 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- import { buildInfo } from '@/buildinfo';
3
-
4
-
5
- describe('buildInfo', () => {
6
-
7
- it('should follow semantic versioning format with optional commit hash', () => {
8
- expect(buildInfo).toMatch(/^\d+\.\d+\.\d+(\+[0-9a-f]+)?$/);
9
- });
10
-
11
- it('should not contain whitespace', () => {
12
- expect(buildInfo).not.toMatch(/\s/);
13
- });
14
-
15
- it('should not be empty or dash', () => {
16
- expect(buildInfo.length).toBeGreaterThan(0);
17
- expect(buildInfo).not.toBe('-');
18
- });
19
-
20
- });
@@ -1,18 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "nodenext",
5
- "moduleResolution": "nodenext",
6
- "emitDeclarationOnly": false,
7
- },
8
- "include": [
9
- "src/**/*.ts"
10
- ],
11
- "exclude": [
12
- "src/dev.ts",
13
- "node_modules",
14
- "dist",
15
- "tests",
16
- "scripts"
17
- ]
18
- }
@@ -1,35 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "lib": [
6
- "ES2022",
7
- "DOM"
8
- ],
9
- "moduleResolution": "bundler",
10
- "strict": true,
11
- "esModuleInterop": true,
12
- "skipLibCheck": true,
13
- "forceConsistentCasingInFileNames": true,
14
- "resolveJsonModule": true,
15
- "declaration": true,
16
- "declarationMap": true,
17
- "emitDeclarationOnly": true,
18
- "outDir": "./dist",
19
- "baseUrl": ".",
20
- "paths": {
21
- "@/*": [
22
- "src/*"
23
- ]
24
- }
25
- },
26
- "include": [
27
- "src/**/*.ts",
28
- "tests/**/*.ts",
29
- "scripts/**/*.ts"
30
- ],
31
- "exclude": [
32
- "node_modules",
33
- "dist"
34
- ]
35
- }
@@ -1 +0,0 @@
1
- {}
@@ -1,158 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import { join } from 'path';
3
- import CDN_MAP from 'scripts/build-cdn-map.json';
4
-
5
-
6
- interface ExportConditions {
7
-
8
- [key: string]: string | undefined;
9
-
10
- import?: string;
11
- types?: string;
12
- browser?: string;
13
- entrypoint?: string;
14
- }
15
-
16
- interface DependencyMap {
17
- [packageName: string]: string;
18
- }
19
-
20
- interface PackageManifest {
21
- version: string;
22
- exports?: Record<string, ExportConditions>;
23
- dependencies?: DependencyMap;
24
- devDependencies?: DependencyMap;
25
- peerDependencies?: DependencyMap;
26
- }
27
-
28
- function getManifest(packageIdentifier?: string): PackageManifest {
29
-
30
- const manifestPath = packageIdentifier
31
- ? join('node_modules', packageIdentifier, 'package.json')
32
- : 'package.json';
33
-
34
- let manifest: PackageManifest;
35
- try {
36
- manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
37
- } catch {
38
- if (packageIdentifier)
39
- throw new Error("[build-cdn] Could not read manifest for '" + packageIdentifier + "' at '" + manifestPath + "'. Is it installed?");
40
- else
41
- throw new Error("[build-cdn] Could not read package manifest at '" + manifestPath + "'.");
42
- }
43
-
44
- return manifest;
45
-
46
- }
47
-
48
- function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
49
-
50
- const exports = packageManifest.exports;
51
- if (!exports) throw new Error('[build-cdn] No exports field found in package.json.');
52
-
53
- const entrypoints = Object.entries(exports)
54
- .map(([key, conditions]) => {
55
- if (!conditions.entrypoint) throw new Error(`[build-cdn] Export '${key}' does not have an 'entrypoint' condition.`);
56
- return conditions.entrypoint;
57
- });
58
-
59
- return entrypoints;
60
-
61
- }
62
-
63
- function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string): string {
64
-
65
- let version: string | undefined;
66
- if (packageIdentifier) {
67
-
68
- const dependencies = {
69
- ...manifest.dependencies,
70
- ...manifest.devDependencies,
71
- ...manifest.peerDependencies,
72
- };
73
-
74
- version = dependencies[packageIdentifier];
75
- if (!version) throw new Error(`[build-cdn] Package '${packageIdentifier}' is not listed in dependencies.`);
76
-
77
- }
78
- else {
79
- if (!manifest.version) throw new Error('[build-cdn] Package manifest does not contain a version field.');
80
- version = manifest.version;
81
- }
82
-
83
- return version;
84
-
85
- }
86
-
87
- function resolveCdnUrl(importSpecifier: string, urlTemplate: string): string {
88
- const manifest = getManifest();
89
- const version = getPackageVersion(manifest, importSpecifier);
90
- return urlTemplate.replace('<VERSION>', version);
91
- }
92
-
93
- const cdnRewritePlugin = {
94
- name: 'cdn-rewrite',
95
- setup(build: any) {
96
-
97
- const resolved = new Map<string, string>();
98
- for (const [importSpecifier, urlTemplate] of Object.entries(CDN_MAP) as [string, string][]) {
99
- const url = resolveCdnUrl(importSpecifier, urlTemplate);
100
- resolved.set(importSpecifier, url);
101
- console.log(`[cdn-rewrite] '${importSpecifier}' → '${url}'`);
102
- }
103
-
104
- build.onResolve({ filter: /.*/ }, (args: any) => {
105
- const url = resolved.get(args.path);
106
- if (url) return { path: url, external: true };
107
- });
108
-
109
- },
110
- };
111
-
112
-
113
- const entrypoints = getManifestEntrypoints(getManifest());
114
- console.log('[build-cdn] Entrypoints:', entrypoints);
115
-
116
- let buildResult;
117
-
118
- console.log('[build-cdn] Starting ESM CDN bundle build...');
119
- buildResult = await Bun.build({
120
- entrypoints,
121
- outdir: 'dist',
122
- naming: '[dir]/[name].bundle.[ext]',
123
- target: 'browser',
124
- format: 'esm',
125
- minify: true,
126
- sourcemap: 'external',
127
- plugins: [cdnRewritePlugin],
128
- });
129
-
130
- if (!buildResult.success) {
131
- console.error('[build-cdn] Build failed:');
132
- for (const message of buildResult.logs) {
133
- console.error(message);
134
- }
135
- process.exit(1);
136
- }
137
- console.log('[build-cdn] ESM CDN bundle build completed successfully.');
138
-
139
- console.log('[build-cdn] Starting IIFE CDN bundle build...');
140
- buildResult = await Bun.build({
141
- entrypoints,
142
- outdir: 'dist',
143
- naming: '[dir]/[name].iife.[ext]',
144
- target: 'browser',
145
- format: 'iife',
146
- minify: true,
147
- sourcemap: 'external',
148
- plugins: [cdnRewritePlugin],
149
- });
150
-
151
- if (!buildResult.success) {
152
- console.error('[build-cdn] Build failed:');
153
- for (const message of buildResult.logs) {
154
- console.error(message);
155
- }
156
- process.exit(1);
157
- }
158
- console.log('[build-cdn] IIFE CDN bundle build completed successfully.');
@@ -1,2 +0,0 @@
1
- // auto-generated by scripts/buildinfo.ts
2
- export const buildInfo = '-';